TriggerExam.cs 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776
  1. using Azure.Cosmos;
  2. using Azure.Messaging.ServiceBus;
  3. using TEAMModelOS.SDK.DI;
  4. using TEAMModelOS.SDK.Extension;
  5. using TEAMModelOS.SDK;
  6. using TEAMModelOS.SDK.Models;
  7. using TEAMModelOS.SDK.Models.Service;
  8. using HTEXLib.COMM.Helpers;
  9. using ClouDASLibx;
  10. using System.Text.Json;
  11. using System.Collections.Generic;
  12. using System.Threading.Tasks;
  13. using System;
  14. using System.Linq;
  15. using TEAMModelOS.SDK.Models.Service.BI;
  16. using Azure.Storage.Blobs.Models;
  17. using System.IO;
  18. using System.Text;
  19. using System.Text.Json.Nodes;
  20. using TEAMModelOS.SDK.Helper.Common.JsonHelper.JsonPath;
  21. using Newtonsoft.Json.Linq;
  22. using TEAMModelOS.SDK.Models.Cosmos.Student;
  23. using HTEXLib.Helpers.ShapeHelpers;
  24. using TEAMModelOS.Models.Dto;
  25. using TEAMModelOS.SDK.Models.Cosmos.Common;
  26. using DocumentFormat.OpenXml.Office2010.Excel;
  27. using DocumentFormat.OpenXml.Drawing.Charts;
  28. using DocumentFormat.OpenXml.Vml;
  29. using System.Net.Http;
  30. using Newtonsoft.Json;
  31. using System.Net;
  32. using System.Security.Policy;
  33. using Microsoft.Extensions.Configuration;
  34. using DocumentFormat.OpenXml.EMMA;
  35. using Microsoft.Extensions.Options;
  36. using TEAMModelOS.Models;
  37. using Microsoft.AspNetCore.Razor.TagHelpers;
  38. namespace TEAMModelOS.FunctionV4
  39. {
  40. public class TriggerExam
  41. {
  42. public static async Task Trigger(CoreAPIHttpService _coreAPIHttpService, AzureCosmosFactory _azureCosmos, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, DingDing _dingDing,
  43. CosmosClient client, JsonElement input, TriggerData data, IHttpClientFactory _httpClient, IConfiguration _configuration, HttpTrigger _httpTrigger)
  44. {
  45. List<ExamClassResult> examClassResults = new();
  46. List<ExamSubject> examSubjects = new();
  47. try
  48. {
  49. if ((data.status != null && data.status.Value == 404))
  50. {
  51. await client.GetContainer(Constant.TEAMModelOS, "Common").DeleteItemStreamAsync(data.id, new PartitionKey(data.code));
  52. ActivityList activity = input.ToObject<ActivityList>();
  53. await IESActivityService.DeleteActivity(_coreAPIHttpService, client, _dingDing, activity);
  54. var table_cancel = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
  55. List<ChangeRecord> records = await table_cancel.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", data.id } });
  56. foreach (var record in records)
  57. {
  58. try
  59. {
  60. await table_cancel.DeleteSingle<ChangeRecord>(record.PartitionKey, record.RowKey);
  61. await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), record.sequenceNumber);
  62. }
  63. catch (Exception)
  64. {
  65. continue;
  66. }
  67. }
  68. await BIStats.SetTypeAddStats(client, _dingDing, data.school, "Exam", -1, careDate: data.startTime);//BI统计增/减量
  69. return;
  70. }
  71. ExamInfo info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(data.id, new Azure.Cosmos.PartitionKey($"{data.code}"));
  72. if (info != null)
  73. {
  74. if (info.scope.Equals("teacher", StringComparison.OrdinalIgnoreCase) || info.scope.Equals("private", StringComparison.OrdinalIgnoreCase))
  75. {
  76. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.examId = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"ExamClassResult-{info.creatorId}") }))
  77. {
  78. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  79. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  80. {
  81. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  82. {
  83. examClassResults.Add(obj.ToObject<ExamClassResult>());
  84. }
  85. }
  86. }
  87. }
  88. else
  89. {
  90. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.examId = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"ExamClassResult-{data.school}") }))
  91. {
  92. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  93. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  94. {
  95. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  96. {
  97. examClassResults.Add(obj.ToObject<ExamClassResult>());
  98. }
  99. }
  100. }
  101. }
  102. var table = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
  103. string PartitionKey = string.Format("{0}{1}{2}", info.code, "-", info.progress);
  104. List<ChangeRecord> records = await table.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", data.id }, { "PartitionKey", PartitionKey } });
  105. //处理科目信息
  106. List<string> sub = new List<string>();
  107. School sc = new();
  108. if (!string.IsNullOrEmpty(info.school) && !info.school.Equals("SYSTEM_NO_SCHOOL")) {
  109. sc = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(info.school, new Azure.Cosmos.PartitionKey("Base"));
  110. }
  111. foreach (ExamSubject subject in info.subjects)
  112. {
  113. sub.Add(subject.id);
  114. }
  115. //整合名单
  116. List<string> classes = ExamService.getClasses(info.classes, info.stuLists);
  117. //ChangeRecord record = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ChangeRecord>(input.Id, new Azure.Cosmos.PartitionKey($"{info.progress}"));
  118. switch (info.progress)
  119. {
  120. case "pending":
  121. var message = new ServiceBusMessage(new { id = data.id, progress = "going", code = data.code }.ToJsonString());
  122. message.ApplicationProperties.Add("name", "Exam");
  123. if (records.Count > 0)
  124. {
  125. try
  126. {
  127. await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), records[0].sequenceNumber);
  128. }
  129. catch (Exception)
  130. {
  131. }
  132. long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), message, DateTimeOffset.FromUnixTimeMilliseconds(data.startTime));
  133. records[0].sequenceNumber = start;
  134. await table.SaveOrUpdate<ChangeRecord>(records[0]);
  135. //await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(record, record.id, new Azure.Cosmos.PartitionKey($"{record.code}"));
  136. }
  137. else
  138. {
  139. long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), message, DateTimeOffset.FromUnixTimeMilliseconds(data.startTime));
  140. //string pk = String.Format("{0}{1}{2}", info.code, "-", "pending");
  141. ChangeRecord changeRecord = new ChangeRecord
  142. {
  143. RowKey = data.id,
  144. PartitionKey = PartitionKey,
  145. sequenceNumber = start,
  146. msgId = message.MessageId
  147. };
  148. await table.Save<ChangeRecord>(changeRecord);
  149. //await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(changeRecord, new Azure.Cosmos.PartitionKey($"{changeRecord.code}"));
  150. }
  151. break;
  152. case "going":
  153. try
  154. {
  155. //向学生或醍摩豆账号发起通知
  156. #region
  157. //Notice notice = new Notice()
  158. //{
  159. // msgId = info.id,
  160. // creation = info.startTime,
  161. // expire = info.endTime,
  162. // creatorId = info.creatorId,
  163. // stuids = studentss,
  164. // tmdids = tmdids,
  165. // type = "notice",//评测参加通知
  166. // priority = "normal",
  167. // school = info.school,
  168. // scope = info.scope,
  169. // //data = new { }.ToJsonString()
  170. // body = new Body { sid = info.id, scode = info.code, spk = info.pk, biztype = "exam-join" }
  171. //};
  172. //var messageBlob = new ServiceBusMessage(notice.ToJsonString());
  173. //messageBlob.ApplicationProperties.Add("name", "Notice");
  174. //await _serviceBus.GetServiceBusClient().SendMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageBlob);
  175. #endregion
  176. //List<string> classes = new List<string>();
  177. //处理活动中间件
  178. List<RGroupList> members = await Activity(_coreAPIHttpService, info, classes, client, _dingDing, sub, examClassResults);
  179. if (examClassResults.Count == 0)
  180. {
  181. foreach (string cla in classes)
  182. {
  183. int m = 0;
  184. RGroupList rGroup = new();
  185. rGroup = members.Where(m => m.id.Equals(cla)).FirstOrDefault();
  186. foreach (ExamSubject subject in info.subjects)
  187. {
  188. string classCode = string.Empty;
  189. string cname = string.Empty;
  190. if (string.IsNullOrEmpty(info.school) || !info.scope.Equals("school", StringComparison.OrdinalIgnoreCase))
  191. {
  192. classCode = "ExamClassResult-" + info.creatorId;
  193. }
  194. else
  195. {
  196. classCode = "ExamClassResult-" + info.school;
  197. }
  198. cname = members.Where(m => m.id.Equals(cla)).FirstOrDefault()?.name;
  199. // 预处理活动中间件信息
  200. ExamClassResult result = new()
  201. {
  202. code = classCode,
  203. examId = info.id,
  204. id = Guid.NewGuid().ToString(),
  205. subjectId = subject.id,
  206. year = info.year,
  207. scope = info.scope
  208. };
  209. result.info.id = cla;
  210. result.info.name = cname;
  211. List<string> ans = new();
  212. List<List<string>> anses = new();
  213. List<List<Details>> marks = new();
  214. List<double> ansPoint = new();
  215. List<(string sId, string scode)> ids = new();
  216. foreach (double p in info.papers[m].point)
  217. {
  218. //Details details = new Details();
  219. //ans.Add(new List<string>());
  220. anses.Add(new List<string>());
  221. marks.Add(new List<Details>());
  222. ansPoint.Add(-1);
  223. }
  224. var sresponse = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(cla, new Azure.Cosmos.PartitionKey($"Class-{info.school}"));
  225. if (sresponse.Status == 200)
  226. {
  227. using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
  228. Class classroom = json.ToObject<Class>();
  229. foreach (SDK.Models.Period period in sc.period)
  230. {
  231. if (period.id.Equals(classroom.periodId))
  232. {
  233. foreach (Semester semester in period.semesters)
  234. {
  235. if (semester.start == 1)
  236. {
  237. int year = DateTimeOffset.UtcNow.Year;
  238. int month = DateTimeOffset.UtcNow.Month;
  239. int day = DateTimeOffset.UtcNow.Day;
  240. int time = 0;
  241. if (month == semester.month)
  242. {
  243. time = day >= semester.day ? 0 : 1;
  244. }
  245. else
  246. {
  247. time = month > semester.month ? 0 : 1;
  248. }
  249. int eyear = year - time;
  250. result.gradeId = (eyear - classroom.year).ToString();
  251. }
  252. }
  253. }
  254. }
  255. //result.info.id = classroom.id;
  256. //result.info.name = classroom.name;
  257. //result.gradeId = classroom.year.ToString();
  258. //处理班级人数
  259. /* await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: $"select c.id from c where c.classId = '{classroom.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{info.school}") }))
  260. {
  261. using var json_stu = await JsonDocument.ParseAsync(item.ContentStream);
  262. if (json_stu.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  263. {
  264. var accounts = json_stu.RootElement.GetProperty("Documents").EnumerateArray();
  265. while (accounts.MoveNext())
  266. {
  267. JsonElement account = accounts.Current;
  268. ids.Add(account.GetProperty("id").GetString());
  269. }
  270. }
  271. }*/
  272. }
  273. /*if (info.scope.Equals("private", StringComparison.OrdinalIgnoreCase))
  274. {
  275. var stuResponse = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemStreamAsync(cla, new Azure.Cosmos.PartitionKey($"GroupList"));
  276. if (stuResponse.Status == 200)
  277. {
  278. using var json = await JsonDocument.ParseAsync(stuResponse.ContentStream);
  279. GroupList stuList = json.ToObject<GroupList>();
  280. //result.info.id = stuList.id;
  281. result.info.name = stuList.name;
  282. //处理发布对象为自选名单(个人)
  283. foreach (Member stus in stuList.members)
  284. {
  285. if (!ids.Contains(stus.id))
  286. {
  287. ids.Add(stus.id);
  288. }
  289. }
  290. }
  291. }
  292. else
  293. {
  294. var stuResponse = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(cla, new Azure.Cosmos.PartitionKey($"GroupList-{info.school}"));
  295. if (stuResponse.Status == 200)
  296. {
  297. using var json = await JsonDocument.ParseAsync(stuResponse.ContentStream);
  298. GroupList stuList = json.ToObject<GroupList>();
  299. //result.info.id = stuList.id;
  300. result.info.name = stuList.name;
  301. //处理发布对象为自选名单(校本)
  302. foreach (Member stus in stuList.members)
  303. {
  304. if (!ids.Contains(stus.id))
  305. {
  306. ids.Add(stus.id);
  307. }
  308. }
  309. }
  310. }*/
  311. foreach (RMember member in rGroup.members)
  312. {
  313. ids.Add((member.id, member.code));
  314. }
  315. //ids = members.Where(c => c.id.Equals(cla)).SelectMany(m => m.members).Select(g => g.id).ToList();
  316. List<string> blobs = new();
  317. if (info.qamode == 2) {
  318. blobs = info.papers.Where(c => c.subjectId.Equals(subject.id)).Select(c => c.blob).ToList();
  319. }
  320. foreach (var (sId, scode) in ids)
  321. {
  322. result.mark.Add(marks);
  323. result.studentIds.Add(sId);
  324. //result.scIds.Add(scode ?? "");
  325. result.studentAnswers.Add(ans);
  326. result.studentScores.Add(ansPoint);
  327. result.ans.Add(anses);
  328. result.sum.Add(0);
  329. result.status.Add(1);
  330. if (info.qamode == 2) {
  331. result.paper.Add(blobs[new Random().Next(blobs.Count)]);
  332. }
  333. }
  334. //result.progress = info.progress;
  335. result.school = info.school;
  336. m++;
  337. await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(result, new Azure.Cosmos.PartitionKey($"{result.code}"));
  338. }
  339. }
  340. }
  341. else
  342. {
  343. //处理单科结算时科目与试卷信息匹配的问题
  344. int gno = 0;
  345. foreach (ExamSubject subject in info.subjects)
  346. {
  347. if (subject.classCount == classes.Count)
  348. {
  349. await createClassResultAsync(info, examClassResults, subject, gno, _azureCosmos, _dingDing, _azureStorage, _httpClient, _configuration);
  350. }
  351. gno++;
  352. }
  353. var isScore = examClassResults.SelectMany(e => e.studentScores).ToList().Exists(c => c.Contains(-1));
  354. int newStatus = 0;
  355. if (!isScore)
  356. {
  357. newStatus = 1;
  358. }
  359. Settlement settlement = await getMore(client, info);
  360. long nowTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  361. //判断评分状态是否发生变化,便于实时的更新评测基本信息
  362. if (info.average != settlement.score || info.sStatus != newStatus)
  363. {
  364. info.sRate = settlement.rate;
  365. info.sStatus = newStatus;
  366. info.updateTime = nowTime;
  367. info.average = settlement.score;
  368. await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ExamInfo>(info, info.id, new PartitionKey(info.code));
  369. }
  370. }
  371. }
  372. catch (Exception e)
  373. {
  374. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测going状态异常{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  375. }
  376. finally
  377. {
  378. // 发送信息通知
  379. var messageEnd = new ServiceBusMessage(new { id = data.id, progress = "finish", code = data.code }.ToJsonString());
  380. messageEnd.ApplicationProperties.Add("name", "Exam");
  381. if (records.Count > 0)
  382. {
  383. long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageEnd, DateTimeOffset.FromUnixTimeMilliseconds(data.endTime));
  384. try
  385. {
  386. await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), records[0].sequenceNumber);
  387. }
  388. catch (Exception)
  389. {
  390. }
  391. records[0].sequenceNumber = end;
  392. await table.SaveOrUpdate<ChangeRecord>(records[0]);
  393. //await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(record, record.id, new Azure.Cosmos.PartitionKey($"{record.code}"));
  394. }
  395. else
  396. {
  397. long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageEnd, DateTimeOffset.FromUnixTimeMilliseconds(data.endTime));
  398. //string pk = String.Format("{0}{1}{2}", info.code, "-", "going");
  399. ChangeRecord changeRecord = new ChangeRecord
  400. {
  401. RowKey = data.id,
  402. PartitionKey = PartitionKey,
  403. sequenceNumber = end,
  404. msgId = messageEnd.MessageId
  405. };
  406. await table.Save<ChangeRecord>(changeRecord);
  407. //await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(changeRecord, new Azure.Cosmos.PartitionKey($"{changeRecord.code}"));
  408. }
  409. }
  410. break;
  411. case "finish":
  412. int fno = 0;
  413. try
  414. {
  415. //用来判定是否完成评分
  416. //bool isScore = true;
  417. await resultStatus(client, examClassResults);
  418. await Activity(_coreAPIHttpService, info, classes, client, _dingDing, sub, examClassResults);
  419. foreach (ExamSubject subject in info.subjects)
  420. {
  421. await createClassResultAsync(info, examClassResults, subject, fno, _azureCosmos, _dingDing, _azureStorage, _httpClient, _configuration);
  422. fno++;
  423. }
  424. Settlement settlement = await getMore(client, info);
  425. var isScore = examClassResults.SelectMany(e => e.studentScores).ToList().Exists(c => c.Contains(-1));
  426. int newStatus = 0;
  427. if (!isScore)
  428. {
  429. newStatus = 1;
  430. }
  431. //判断均分是否发生变化,便于实时的更新评测基本信息
  432. if (info.sRate != settlement.rate || info.average != settlement.score || info.sStatus != newStatus || info.qRate != settlement.qrate)
  433. {
  434. info.sRate = settlement.rate;
  435. info.average = settlement.score;
  436. info.sStatus = newStatus;
  437. info.lostStu = settlement.stus;
  438. info.stuCount = settlement.total;
  439. info.qRate = settlement.qrate;
  440. //新增数据推送 obj => Portrait
  441. Portrait portrait = new()
  442. {
  443. schoolCode = info.school,
  444. periodId = info.period.id,
  445. subjectId = "subject_intelligence"
  446. };
  447. //作答合格率
  448. var sta = examClassResults.SelectMany(x => x.status).ToList();
  449. /* var stus = examClassResults.SelectMany(x => x.studentIds).ToList();
  450. var stuScores = examClassResults.SelectMany(x => x.studentScores).ToList();*/
  451. var ansCount = sta.Where(x => x == 0).ToList();
  452. var persent = ansCount.Count * 1.0 / sta.Count * 100;
  453. var period = sc.period.Where(x => x.id.Equals(info.period.id)).FirstOrDefault();
  454. List<string> subjects = info.subjects.Select(x => x.id).ToList();
  455. //获取学期信息
  456. if (null != period && persent >= 60 && !subjects.Contains("subject_painting") && !subjects.Contains("subject_music")) {
  457. var (currSemester, studyYear, currSemesterDate, date, nextSemester) = SchoolService.GetSemester(period, info.startTime);
  458. //获取学生信息
  459. (List<RMember> rmembers, List<RGroupList> groups) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, info.classes, info.school);
  460. foreach (var member in rmembers)
  461. {
  462. if (info.lostStu.Contains(member.id))
  463. {
  464. continue;
  465. }
  466. PortraitStudent student = new()
  467. {
  468. studentId = member.id,
  469. name = member.name,
  470. classId = member.classId
  471. };
  472. var ec = examClassResults.Where(c => c.studentIds.Contains(member.id)).ToList();
  473. double scores = 0;
  474. List<(string subjectId, double score)> subScore = new();
  475. foreach (var eclass in ec) {
  476. int index_stu = eclass.studentIds.IndexOf(member.id);
  477. scores += eclass.sum[index_stu];
  478. subScore.Add((eclass.subjectId, eclass.sum[index_stu]));
  479. }
  480. SemesterData semesterData = new()
  481. {
  482. examName = info.name,
  483. examId = info.id,
  484. examDate = info.startTime,
  485. examType = info.examType?.name,
  486. year = info.year,
  487. semesterId = currSemester.id,
  488. totalScore = info.papers.SelectMany(x => x.point).Sum(),
  489. sumScore = scores,
  490. excellenceRate = 0,
  491. passRate = 0,
  492. };
  493. int index = 0;
  494. foreach (var sj in info.subjects)
  495. {
  496. ItemScore item = new()
  497. {
  498. id = sj.id,
  499. name = sj.name,
  500. score = subScore.Where(c => c.subjectId.Equals(sj.id)).FirstOrDefault().score,
  501. time = info.startTime,
  502. totalScore = info.papers[index].point.Sum(),
  503. type = sj.id
  504. };
  505. index++;
  506. semesterData.itemScore.Add(item);
  507. }
  508. student.semesterData.Add(semesterData);
  509. portrait.students.Add(student);
  510. }
  511. string location = $"{Environment.GetEnvironmentVariable("Option:Location")}";
  512. var (status, json) = await _httpTrigger.RequestHttpTrigger(portrait, location, "upsert-student-portrait");
  513. }
  514. //PortraitStudent student = new();
  515. //处理试卷活动结束统计账户信息
  516. List<FMember> idList = await GroupListService.GetFinishMemberInfo(_coreAPIHttpService, client, _dingDing, info.school, info.classes, info.stuLists, null);
  517. info.staffIds = idList;
  518. await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ExamInfo>(info, info.id, new Azure.Cosmos.PartitionKey(info.code));
  519. }
  520. }
  521. catch (Exception e)
  522. {
  523. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测finish状态异常{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  524. }
  525. break;
  526. }
  527. }
  528. }
  529. catch (CosmosException e)
  530. {
  531. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-CosmosDB异常{e.Message}\n{e.StackTrace}\n{e.Status}", GroupNames.醍摩豆服務運維群組);
  532. }
  533. catch (Exception e)
  534. {
  535. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-评测结算异常{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  536. }
  537. }
  538. public static async Task resultStatus(CosmosClient client, List<ExamClassResult> examClassResults)
  539. {
  540. List<Task<ItemResponse<ExamClassResult>>> tasks = new();
  541. //结算单科单班的标准差和平均分
  542. foreach (ExamClassResult classResult in examClassResults)
  543. {
  544. //标记单科单班总得分
  545. double subScore = 0;
  546. //标准差
  547. double sPowSum = 0;
  548. List<double> newSumScore = new List<double>();
  549. List<double> effectiveScore = new List<double>();
  550. int lostStu = classResult.status.Where(c => c == 1).ToList().Count;
  551. var scount = classResult.studentIds.Count - lostStu;
  552. int index = 0;
  553. if (classResult.status.Count > 0)
  554. {
  555. foreach (var sta in classResult.status)
  556. {
  557. if (sta == 1)
  558. {
  559. for (int i = 0; i < classResult.studentScores[index].Count; i++)
  560. {
  561. if (classResult.studentScores[index][i] == -1)
  562. {
  563. classResult.studentScores[index][i] = 0;
  564. }
  565. }
  566. }
  567. else if (sta == 0)
  568. {
  569. //var ans = classResult.studentAnswers[index];
  570. //该学生缺考,历史数据的判定
  571. //if (ans.Count == 0)
  572. //{
  573. for (int i = 0; i < classResult.studentScores[index].Count; i++)
  574. {
  575. if (classResult.studentScores[index][i] == -1)
  576. {
  577. classResult.studentScores[index][i] = 0;
  578. }
  579. }
  580. /*if (ans.Count == 0)
  581. {
  582. classResult.status[index] = 1;
  583. } */
  584. //}
  585. }
  586. index++;
  587. }
  588. }
  589. else
  590. {
  591. List<int> sta = new();
  592. foreach (var id in classResult.studentIds)
  593. {
  594. sta.Add(0);
  595. }
  596. classResult.status = sta;
  597. foreach (var ans in classResult.studentAnswers)
  598. {
  599. //该学生缺考,历史数据的判定
  600. if (ans.Count == 0)
  601. {
  602. for (int i = 0; i < classResult.studentScores[index].Count; i++)
  603. {
  604. if (classResult.studentScores[index][i] == -1)
  605. {
  606. classResult.studentScores[index][i] = 0;
  607. }
  608. }
  609. classResult.status[index] = 1;
  610. }
  611. index++;
  612. }
  613. }
  614. int sIndex = 0;
  615. foreach (List<double> sc in classResult.studentScores)
  616. {
  617. List<double> newSc = new List<double>();
  618. foreach (double ssc in sc)
  619. {
  620. if (ssc == -1)
  621. {
  622. newSc.Add(0);
  623. }
  624. else
  625. {
  626. newSc.Add(ssc);
  627. }
  628. }
  629. double nc = Math.Round(newSc.Sum(), 2);
  630. if (classResult.status[sIndex] == 0)
  631. {
  632. effectiveScore.Add(nc);
  633. };
  634. newSumScore.Add(nc);
  635. subScore += nc;
  636. classResult.sum[sIndex] = nc;
  637. sIndex++;
  638. }
  639. double rateScore = scount > 0 ? Math.Round(subScore * 1.0 / scount, 2) : 0;
  640. //有效分数
  641. foreach (double scs in effectiveScore)
  642. {
  643. sPowSum += Math.Pow(scs - rateScore, 2);
  644. }
  645. classResult.standard = Math.Round(scount > 0 ? Math.Pow(sPowSum / scount, 0.5) : 0, 2);
  646. classResult.average = scount > 0 ? Math.Round(subScore / scount, 2) : 0;
  647. classResult.progress = true;
  648. tasks.Add(client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"{classResult.code}")));
  649. }
  650. await Task.WhenAll(tasks);
  651. }
  652. public static async Task<Settlement> getMore(CosmosClient client, ExamInfo info)
  653. {
  654. //计算单次考试简易统计信息
  655. Settlement settlement = new();
  656. List<ExamResult> examResults = new();
  657. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamResult>(
  658. queryText: $"select value(c) from c where c.examId = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"ExamResult-{info.id}") }))
  659. {
  660. examResults.Add(item);
  661. }
  662. if (examResults.Count > 0)
  663. {
  664. //记录某次考试所有学生得分总分
  665. double score = 0;
  666. double allScore = 0;
  667. int stuCount = 0;
  668. //标准差
  669. double powSum = 0;
  670. List<string> losStu = new List<string>();
  671. //当前完成考试得人数
  672. int total = examResults[0].studentIds.Distinct().Count();
  673. //先与第一个值取并集
  674. losStu = losStu.Union(examResults[0].lostStus).ToList();
  675. foreach (ExamResult examResult in examResults)
  676. {
  677. //取交集
  678. losStu = losStu.Intersect(examResult.lostStus).ToList();
  679. }
  680. //处理缺考的学生
  681. List<string> stus = examResults[0].studentIds.Except(losStu).ToList();
  682. foreach (ExamResult examResult in examResults)
  683. {
  684. foreach (var id in stus)
  685. {
  686. int index = examResult.studentIds.IndexOf(id);
  687. score += examResult.studentScores[index].Sum();
  688. }
  689. }
  690. stuCount = total - losStu.Count;
  691. double NewsRateScore = stuCount > 0 ? Math.Round(score * 1.0 / stuCount, 2) : 0;
  692. foreach (PaperSimple simple in info.papers)
  693. {
  694. allScore += simple.point.Sum();
  695. }
  696. //计算全科标准差
  697. foreach (string id in stus)
  698. {
  699. double sc = 0;
  700. foreach (ExamResult result in examResults)
  701. {
  702. if (result.studentScores.Count > 0)
  703. {
  704. sc += result.studentScores[result.studentIds.IndexOf(id)].Sum();
  705. }
  706. }
  707. powSum += Math.Pow(sc - NewsRateScore, 2);
  708. }
  709. info.standard = Math.Round(total - losStu.Count > 0 ? Math.Pow(powSum / (total - losStu.Count), 0.5) : 0, 2);
  710. double NewsRate = allScore > 0 ? Math.Round(NewsRateScore / allScore * 100, 2) : 0;
  711. double qrate = Math.Round(total > 0 ? losStu.Count * 1.0 / total * 100 : 0, 2);
  712. settlement.rate = NewsRate;
  713. settlement.score = NewsRateScore;
  714. settlement.stus = losStu;
  715. settlement.total = total;
  716. settlement.qrate = qrate;
  717. }
  718. return settlement;
  719. }
  720. //处理全部学生选题计数
  721. public static async Task examRecordCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no, ExamResult er, List<ExamClassResult> classResults, AzureCosmosFactory _azureCosmos)
  722. {
  723. try
  724. {
  725. List<double> scores = new List<double>();
  726. foreach (List<double> sc in er.studentScores)
  727. {
  728. scores.Add(sc.Sum());
  729. }
  730. //确定高分组 最低分数
  731. //var srowallorder = scores.EnumerateIndexed().OrderByDescending(g => g.Item2); //各生總分排序
  732. //var srowallorder = scores.OrderByDescending(g => g);
  733. double[] point = StringHelper.ListTodouble(er.paper.point);
  734. double[,] result = StringHelper.ListToDouble(er.studentScores);
  735. var cdm = new ClouDASMatrix(result, point);
  736. scores.Sort((s1, s2) => { return s2.CompareTo(s1); });
  737. int rhwCount = cdm.SH.Count();
  738. double rhw = cdm.SH.LastOrDefault().Item2;
  739. int rhlCount = cdm.SL.Count();
  740. double rhl = cdm.SL.FirstOrDefault().Item2;
  741. List<string> phs = new();
  742. List<string> pls = new();
  743. //分别获取高分组低分组人员
  744. foreach (var ph in cdm.SH)
  745. {
  746. phs.Add(er.studentIds[ph.Item1]);
  747. }
  748. foreach (var pl in cdm.SL)
  749. {
  750. pls.Add(er.studentIds[pl.Item1]);
  751. }
  752. /* if (scores.Count > 3)
  753. {
  754. rhwCount = Convert.ToInt32(Math.Floor(scores.Count * 0.27));
  755. rhw = rhwCount > 0 ? scores[rhwCount - 1] : 0;
  756. rhlCount = Convert.ToInt32(Math.Ceiling(scores.Count * 0.73));
  757. rhl = rhlCount > 0 ? scores[rhlCount] : 0;
  758. }
  759. else
  760. {
  761. rhwCount = Convert.ToInt32(Math.Floor(scores.Count * 0.27));
  762. rhw = rhwCount > 0 ? scores[rhwCount] : 0;
  763. rhlCount = Convert.ToInt32(Math.Ceiling(scores.Count * 0.73));
  764. rhl = rhlCount > 0 ? scores[rhlCount - 1] : 0;
  765. }*/
  766. /*int rhwCount = Convert.ToInt32(Math.Floor(scores.Count * 0.27));
  767. double rhw = rhwCount > 0 ? scores[rhwCount-1] : 0;
  768. //var rhww = srowallorder.Take(Convert.ToInt32(Math.Floor(scores.Count * 0.27)));
  769. //确定低分组 最高分数
  770. //scores.Sort((s1, s2) => { return s1.CompareTo(s2); });
  771. int rhlCount = Convert.ToInt32(Math.Ceiling(scores.Count * 0.73));
  772. double rhl = rhlCount > 0 ? scores[rhlCount-1] : 0;*/
  773. //var rhll = srowallorder.Skip(Convert.ToInt32(Math.Ceiling(scores.Count * 0.73)));
  774. //存放高分组学生ID
  775. List<string> phId = new();
  776. List<string> plId = new();
  777. List<List<List<string>>> opth = new();
  778. List<List<List<string>>> optl = new();
  779. List<double> akp = await knowledgeCount(info, subject, _dingDing, no, classResults, rhwCount, rhw, rhlCount, rhl, _azureCosmos);
  780. List<double> afp = await fieldCount(info, subject, _dingDing, no, classResults, rhwCount, rhw, rhlCount, rhl, _azureCosmos);
  781. int PHCount = 0;
  782. int PLCount = 0;
  783. foreach (ExamClassResult classResult in classResults)
  784. {
  785. if (classResult.subjectId.Equals(subject.id))
  786. {
  787. foreach (string id in classResult.studentIds)
  788. {
  789. int index = classResult.studentIds.IndexOf(id);
  790. if (classResult.studentScores.Count > 0)
  791. {
  792. if (phs.Contains(id))
  793. {
  794. if (classResult.ans.Count > 0)
  795. {
  796. opth.Add(classResult.ans[index]);
  797. PHCount++;
  798. continue;
  799. }
  800. }
  801. if (pls.Contains(id))
  802. {
  803. if (classResult.ans.Count > 0)
  804. {
  805. optl.Add(classResult.ans[index]);
  806. PLCount++;
  807. continue;
  808. }
  809. }
  810. }
  811. }
  812. }
  813. }
  814. er.phc = getMore(info, no, opth);
  815. er.plc = getMore(info, no, optl);
  816. er.afp = afp;
  817. er.akp = akp;
  818. }
  819. catch (Exception ex)
  820. {
  821. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测作答记录结算异常{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  822. }
  823. }
  824. public static async Task<List<RGroupList>> Activity(CoreAPIHttpService _coreAPIHttpService, ExamInfo info, List<string> classes, CosmosClient client, DingDing _dingDing, List<string> sub, List<ExamClassResult> results)
  825. {
  826. List<(string pId, List<string> gid)> ps = new List<(string pId, List<string> gid)>();
  827. if (info.groupLists.Count > 0)
  828. {
  829. var group = info.groupLists;
  830. foreach (var gp in group)
  831. {
  832. foreach (KeyValuePair<string, List<string>> pp in gp)
  833. {
  834. ps.Add((pp.Key, pp.Value));
  835. }
  836. }
  837. }
  838. (List<RMember> tchList, List<RGroupList> classLists) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, classes, info.school, ps);
  839. var addStudentsCls = tchList.FindAll(x => x.type == 2);
  840. var addTmdidsCls = tchList.FindAll(x => x.type == 1);
  841. List<StuActivity> stuActivities = new List<StuActivity>();
  842. List<StuActivity> tmdActivities = new List<StuActivity>();
  843. var papers = info.papers.GroupBy(c => c.subjectId).Select(x => new {
  844. subject = x.Key,
  845. blob = x.ToList().Select(z => z.blob).ToList() });
  846. bool flag = info.papers.Exists(c => c.subjectId != null);
  847. //var subs = info.papers.Select(z => z.subjectId).Distinct().ToList();
  848. if (addTmdidsCls.IsNotEmpty())
  849. {
  850. addTmdidsCls.ForEach(x =>
  851. {
  852. HashSet<string> classIds = new HashSet<string>();
  853. classLists.ForEach(z =>
  854. {
  855. z.members.ForEach(y =>
  856. {
  857. if (y.id.Equals(x.id) && y.type == 1)
  858. {
  859. classIds.Add(z.id);
  860. }
  861. });
  862. });
  863. bool iss = false;
  864. //标记学生作答状态
  865. int ts = 0;
  866. if (results.Count > 0)
  867. {
  868. foreach (ExamClassResult exam in results)
  869. {
  870. int index = exam.studentIds.IndexOf(x.id);
  871. if (index != -1)
  872. {
  873. if (exam.studentAnswers[index].Count > 0)
  874. {
  875. bool flag = exam.studentScores[index].Exists(x => x == -1);
  876. if (!flag)
  877. {
  878. ts = 1;
  879. iss = true;
  880. break;
  881. }
  882. else
  883. {
  884. ts = 0;
  885. }
  886. }
  887. else
  888. {
  889. ts = -1;
  890. }
  891. }
  892. }
  893. }
  894. else
  895. {
  896. ts = -1;
  897. }
  898. tmdActivities.Add(new StuActivity
  899. {
  900. pk = "Activity",
  901. id = info.id,
  902. code = $"Activity-{x.id}",
  903. type = "Exam",
  904. name = info.name,
  905. source = info.source,
  906. startTime = info.startTime,
  907. endTime = info.endTime,
  908. scode = info.code,
  909. scope = info.scope,
  910. school = info.school,
  911. creatorId = info.creatorId,
  912. subjects = sub,
  913. blob = null,
  914. paper = flag ? papers.Select(c => new {
  915. c.subject,
  916. blob = c.blob[new Random().Next(c.blob.Count)]
  917. }) : "",
  918. owner = info.owner,
  919. createTime = info.createTime,
  920. taskStatus = ts,
  921. qamode = info.qamode,
  922. ext = new Dictionary<string, JsonElement>() { { "type", info.examType.ToJsonString().ToObject<JsonElement>() },
  923. { "subjects", info.subjects.ToJsonString().ToObject<JsonElement>() } },
  924. sStatus = iss ? 1 : 0,
  925. classIds = classIds.ToList()
  926. }); ;
  927. });
  928. }
  929. if (addStudentsCls.IsNotEmpty())
  930. {
  931. addStudentsCls.ForEach(x =>
  932. {
  933. HashSet<string> classIds = new HashSet<string>();
  934. classLists.ForEach(z =>
  935. {
  936. z.members.ForEach(y =>
  937. {
  938. if (y.id.Equals(x.id) && y.code.Equals(info.school) && y.type == 2)
  939. {
  940. classIds.Add(z.id);
  941. }
  942. });
  943. });
  944. bool iss = false;
  945. //标记学生作答状态
  946. int ts = 0;
  947. if (results.Count > 0)
  948. {
  949. foreach (ExamClassResult exam in results)
  950. {
  951. int index = exam.studentIds.IndexOf(x.id);
  952. if (index != -1)
  953. {
  954. if (exam.studentAnswers[index].Count > 0)
  955. {
  956. bool flag = exam.studentScores[index].Exists(x => x == -1);
  957. if (!flag)
  958. {
  959. ts = 1;
  960. iss = true;
  961. break;
  962. }
  963. else
  964. {
  965. ts = 0;
  966. }
  967. }
  968. else
  969. {
  970. ts = -1;
  971. }
  972. }
  973. }
  974. }
  975. else
  976. {
  977. ts = -1;
  978. }
  979. stuActivities.Add(new StuActivity
  980. {
  981. pk = "Activity",
  982. id = info.id,
  983. code = $"Activity-{x.code.Replace("Base-", "")}-{x.id}",
  984. type = "Exam",
  985. name = info.name,
  986. source = info.source,
  987. startTime = info.startTime,
  988. endTime = info.endTime,
  989. scode = info.code,
  990. scope = info.scope,
  991. school = info.school,
  992. creatorId = info.creatorId,
  993. subjects = sub,
  994. blob = null,
  995. paper = flag ? papers.Select(c => new {
  996. c.subject,
  997. blob = c.blob[new Random().Next(c.blob.Count)]
  998. }) : "",
  999. owner = info.owner,
  1000. classIds = classIds.ToList(),
  1001. createTime = info.createTime,
  1002. qamode = info.qamode,
  1003. ext = new Dictionary<string, JsonElement>() { { "type", info.examType.ToJsonString().ToObject<JsonElement>() },
  1004. { "subjects", info.subjects.ToJsonString().ToObject<JsonElement>() } },
  1005. taskStatus = ts,
  1006. sStatus = iss ? 1 : 0,
  1007. });
  1008. });
  1009. }
  1010. await IESActivityService.SaveStuActivity(client, _dingDing, stuActivities, tmdActivities, null);
  1011. return classLists;
  1012. }
  1013. public static async Task<List<double>> knowledgeCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no, List<ExamClassResult> classResults,
  1014. double rhwCount, double rhw, double rhlCount, double rhl, AzureCosmosFactory _azureCosmos)
  1015. {
  1016. List<double> akp = new();
  1017. try
  1018. {
  1019. int phcount = 0;
  1020. int plcount = 0;
  1021. //存放并去重知识点
  1022. HashSet<string> kname = new HashSet<string>();
  1023. if (info.papers[no].knowledge.Count > 0)
  1024. {
  1025. info.papers[no].knowledge.ForEach(kno =>
  1026. {
  1027. kno.ForEach(k =>
  1028. {
  1029. kname.Add(k);
  1030. });
  1031. });
  1032. List<string> knowledgeName = new List<string>();
  1033. foreach (string cla in kname)
  1034. {
  1035. knowledgeName.Add(cla);
  1036. }
  1037. for (int k = 0; k < knowledgeName.Count; k++)
  1038. {
  1039. if (null == knowledgeName[k])
  1040. {
  1041. knowledgeName.Remove(knowledgeName[k]);
  1042. }
  1043. }
  1044. foreach (ExamClassResult classResult in classResults)
  1045. {
  1046. if (classResult.subjectId.Equals(subject.id))
  1047. {
  1048. //List<int> phc = new List<int>();
  1049. List<int> ph = new List<int>();
  1050. List<int> pl = new List<int>();
  1051. List<int> pc = new List<int>();
  1052. List<double> persent = new List<double>();
  1053. int lostStu = classResult.status.Where(c => c == 1).ToList().Count;
  1054. for (int i = 0; i < knowledgeName.Count; i++)
  1055. {
  1056. //初始化单个知识点得分
  1057. double score = 0;
  1058. int n = 0;
  1059. int phCount = 0;
  1060. int plCount = 0;
  1061. int pCount = 0;
  1062. double classScore = 0;
  1063. foreach (List<string> str in info.papers[no].knowledge)
  1064. {
  1065. if (str.Contains(knowledgeName[i]))
  1066. {
  1067. var itemPersent = str.Count > 0 ? 1 / Convert.ToDouble(str.Count) : 0;
  1068. classScore += info.papers[no].point.Count > 0 ? (info.papers[no].point[n] * itemPersent) : 0;
  1069. foreach (string id in classResult.studentIds)
  1070. {
  1071. int index = classResult.studentIds.IndexOf(id);
  1072. if (classResult.studentScores.Count > 0)
  1073. {
  1074. if (classResult.studentScores[index].Count > 0)
  1075. {
  1076. double realScore = classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n] * itemPersent;
  1077. score += realScore;
  1078. //score += classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n] * itemPersent;
  1079. if (classResult.studentScores[index].Sum() >= rhw && phcount < rhwCount)
  1080. {
  1081. if (classResult.studentScores[index][n] <= 0)
  1082. {
  1083. phCount++;
  1084. }
  1085. phcount++;
  1086. continue;
  1087. }
  1088. if (classResult.studentScores[index].Sum() <= rhl && plcount < (info.stuCount - rhlCount))
  1089. {
  1090. if (classResult.studentScores[index][n] <= 0)
  1091. {
  1092. plCount++;
  1093. }
  1094. plcount++;
  1095. continue;
  1096. }
  1097. if (classResult.studentScores[index][n] <= 0)
  1098. {
  1099. pCount++;
  1100. }
  1101. }
  1102. }
  1103. }
  1104. }
  1105. n++;
  1106. }
  1107. pc.Add(pCount);
  1108. ph.Add(phCount);
  1109. pl.Add(plCount);
  1110. double per = classResult.studentIds.Count - lostStu > 0 ? Math.Round(score / (classResult.studentIds.Count - lostStu), 2) : 0;
  1111. persent.Add(classScore > 0 ? Math.Round(per * 1.0 / classScore, 2) : 0);
  1112. }
  1113. classResult.phc = ph;
  1114. classResult.plc = pl;
  1115. classResult.pc = pc;
  1116. classResult.krate = persent;
  1117. }
  1118. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new Azure.Cosmos.PartitionKey($"{classResult.code}"));
  1119. }
  1120. foreach (string k in knowledgeName)
  1121. {
  1122. double score = 0;
  1123. double allScore = 0;
  1124. int count = 0;
  1125. int m = 0;
  1126. foreach (List<string> str in info.papers[no].knowledge)
  1127. {
  1128. if (str.Contains(k))
  1129. {
  1130. var itemPersent = str.Count > 0 ? 1 / Convert.ToDouble(str.Count) : 0;
  1131. allScore += info.papers[no].point.Count > 0 ? info.papers[no].point[m] * itemPersent : 0;
  1132. }
  1133. m++;
  1134. }
  1135. foreach (ExamClassResult result in classResults)
  1136. {
  1137. if (result.subjectId.Equals(subject.id))
  1138. {
  1139. int n = 0;
  1140. foreach (List<string> str in info.papers[no].knowledge)
  1141. {
  1142. if (str.Contains(k))
  1143. {
  1144. var itemPersent = str.Count > 0 ? 1 / Convert.ToDouble(str.Count) : 0;
  1145. if (result.studentScores.Count > 0)
  1146. {
  1147. foreach (List<double> sc in result.studentScores)
  1148. {
  1149. double tsc = sc[n] == -1 ? 0 : sc[n];
  1150. score += (tsc * itemPersent);
  1151. }
  1152. }
  1153. }
  1154. n++;
  1155. }
  1156. count += result.studentIds.Count;
  1157. }
  1158. }
  1159. double per = count - info.lostStu.Count > 0 ? Math.Round(score / (count - info.lostStu.Count), 2) : 0;
  1160. akp.Add(allScore > 0 ? Math.Round(per / allScore, 2) : 0);
  1161. }
  1162. }
  1163. return akp;
  1164. }
  1165. catch (Exception ex)
  1166. {
  1167. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测知识点结算异常{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1168. return null;
  1169. }
  1170. }
  1171. public static async Task<List<double>> fieldCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no, List<ExamClassResult> classResults,
  1172. double rhwCount, double rhw, double rhlCount, double rhl, AzureCosmosFactory _azureCosmos)
  1173. {
  1174. List<double> afp = new();
  1175. try
  1176. {
  1177. int phcount = 0;
  1178. int plcount = 0;
  1179. //存放并去重知识点
  1180. List<int> knowledgeName = new List<int>() { 1, 2, 3, 4, 5, 6 };
  1181. /* knowledgeName.Add(1);
  1182. knowledgeName.Add(2);
  1183. knowledgeName.Add(3);
  1184. knowledgeName.Add(4);
  1185. knowledgeName.Add(5);
  1186. knowledgeName.Add(6);*/
  1187. foreach (ExamClassResult classResult in classResults)
  1188. {
  1189. if (classResult.subjectId.Equals(subject.id))
  1190. {
  1191. //List<int> phc = new List<int>();
  1192. List<int> ph = new List<int>();
  1193. List<int> pl = new List<int>();
  1194. List<int> pc = new List<int>();
  1195. List<double> persent = new List<double>();
  1196. int lostStu = classResult.status.Where(c => c == 1).ToList().Count;
  1197. for (int i = 0; i < knowledgeName.Count; i++)
  1198. {
  1199. //初始化单个知识点得分
  1200. double score = 0;
  1201. int n = 0;
  1202. int phCount = 0;
  1203. int plCount = 0;
  1204. int pCount = 0;
  1205. double classScore = 0;
  1206. if (info.papers[no].field.Count > 0)
  1207. {
  1208. foreach (int str in info.papers[no].field)
  1209. {
  1210. if (str == knowledgeName[i])
  1211. {
  1212. var itemPersent = 1;
  1213. classScore += info.papers[no].point.Count > 0 ? info.papers[no].point[n] * itemPersent : 0;
  1214. foreach (string id in classResult.studentIds)
  1215. {
  1216. int index = classResult.studentIds.IndexOf(id);
  1217. if (classResult.studentScores.Count > 0)
  1218. {
  1219. if (classResult.studentScores[index].Count > 0)
  1220. {
  1221. score += classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n];
  1222. if (classResult.studentScores[index].Sum() >= rhw && phcount < rhwCount)
  1223. {
  1224. if (classResult.studentScores[index][n] <= 0)
  1225. {
  1226. phCount++;
  1227. }
  1228. phcount++;
  1229. continue;
  1230. }
  1231. if (classResult.studentScores[index].Sum() <= rhl && plcount < (info.stuCount - rhlCount))
  1232. {
  1233. if (classResult.studentScores[index][n] <= 0)
  1234. {
  1235. plCount++;
  1236. }
  1237. plcount++;
  1238. continue;
  1239. }
  1240. if (classResult.studentScores[index][n] <= 0)
  1241. {
  1242. pCount++;
  1243. }
  1244. }
  1245. }
  1246. }
  1247. }
  1248. n++;
  1249. }
  1250. pc.Add(pCount);
  1251. ph.Add(phCount);
  1252. pl.Add(plCount);
  1253. double per = classResult.studentIds.Count - lostStu > 0 ? Math.Round(score / (classResult.studentIds.Count - lostStu), 2) : 0;
  1254. persent.Add(classScore > 0 ? Math.Round(per / classScore, 2) : 0);
  1255. }
  1256. }
  1257. classResult.fphc = ph;
  1258. classResult.fplc = pl;
  1259. classResult.fpc = pc;
  1260. classResult.frate = persent;
  1261. }
  1262. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new Azure.Cosmos.PartitionKey($"{classResult.code}"));
  1263. }
  1264. for (int i = 0; i < knowledgeName.Count; i++)
  1265. {
  1266. double score = 0;
  1267. double allScore = 0;
  1268. int count = 0;
  1269. int m = 0;
  1270. foreach (int str in info.papers[no].field)
  1271. {
  1272. if (str == knowledgeName[i])
  1273. {
  1274. var itemPersent = 1;
  1275. allScore += info.papers[no].point.Count > 0 ? info.papers[no].point[m] * itemPersent : 0;
  1276. }
  1277. m++;
  1278. }
  1279. foreach (ExamClassResult result in classResults)
  1280. {
  1281. if (result.subjectId.Equals(subject.id))
  1282. {
  1283. int n = 0;
  1284. foreach (int str in info.papers[no].field)
  1285. {
  1286. var itemPersent = 1;
  1287. if (str == knowledgeName[i])
  1288. {
  1289. if (result.studentScores.Count > 0)
  1290. {
  1291. foreach (List<double> sc in result.studentScores)
  1292. {
  1293. double tsc = sc[n] == -1 ? 0 : sc[n];
  1294. score += tsc * itemPersent;
  1295. }
  1296. }
  1297. }
  1298. n++;
  1299. }
  1300. count += result.studentIds.Count;
  1301. }
  1302. }
  1303. double per = count - info.lostStu.Count > 0 ? Math.Round(score / (count - info.lostStu.Count), 2) : 0;
  1304. afp.Add(allScore > 0 ? Math.Round(per / allScore, 2) : 0);
  1305. }
  1306. return afp;
  1307. }
  1308. catch (Exception ex)
  1309. {
  1310. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测认知层次结算异常{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1311. return null;
  1312. }
  1313. }
  1314. //处理选题计数
  1315. public static List<Dictionary<string, int>> getMore(ExamInfo info, int no, List<List<List<string>>> list)
  1316. {
  1317. List<Dictionary<string, int>> recorde = new List<Dictionary<string, int>>();
  1318. try
  1319. {
  1320. for (int i = 0; i < info.papers[no].answers.Count; i++)
  1321. {
  1322. if (info.papers[no].answers[i].Count <= 0)
  1323. {
  1324. recorde.Add(new Dictionary<string, int>());
  1325. continue;
  1326. }
  1327. Dictionary<string, int> optCount = new Dictionary<string, int>();
  1328. foreach (List<List<string>> stu in list)
  1329. {
  1330. if (stu.Count == info.papers[no].answers.Count)
  1331. {
  1332. var item = stu[i];
  1333. foreach (string opt in item)
  1334. {
  1335. if (optCount.ContainsKey(opt))
  1336. {
  1337. optCount[opt] = optCount[opt] + 1;
  1338. }
  1339. else
  1340. {
  1341. optCount[opt] = 1;
  1342. }
  1343. }
  1344. }
  1345. }
  1346. recorde.Add(optCount);
  1347. }
  1348. return recorde;
  1349. }
  1350. catch (Exception)
  1351. {
  1352. return recorde;
  1353. }
  1354. }
  1355. public static async Task createClassResultAsync(ExamInfo info, List<ExamClassResult> examClassResults, ExamSubject subject, int no, AzureCosmosFactory _azureCosmos, DingDing _dingDing, AzureStorageFactory _azureStorage, IHttpClientFactory _httpClient, IConfiguration _configuration)
  1356. {
  1357. //保证试卷信息与科目信息同步
  1358. ExamResult result = new ExamResult();
  1359. //人数总和
  1360. int Count = 0;
  1361. int m = 0;
  1362. double score = 0;
  1363. //标准差
  1364. //double powSum = 0;
  1365. double allScore = info.papers[no].point.Sum();
  1366. List<ClassRange> classRanges = new List<ClassRange>();
  1367. List<string> lostStu = new List<string>();
  1368. List<double> csRate = new List<double>();
  1369. List<List<List<string>>> opt = new List<List<List<string>>>();
  1370. //List<Task<ItemResponse<ExamClassResult>>> tasks = new();
  1371. foreach (ExamClassResult classResult in examClassResults)
  1372. {
  1373. double classSrate = 0;
  1374. if (classResult.subjectId.Equals(subject.id))
  1375. {
  1376. foreach (List<List<string>> op in classResult.ans)
  1377. {
  1378. opt.Add(op);
  1379. }
  1380. //记录缺考学生索引位置
  1381. int index_stu = 0;
  1382. foreach (var ans in classResult.studentAnswers)
  1383. {
  1384. if (ans.Count == 0)
  1385. {
  1386. if (!lostStu.Contains(classResult.studentIds[index_stu]))
  1387. {
  1388. lostStu.Add(classResult.studentIds[index_stu]);
  1389. }
  1390. }
  1391. else
  1392. {
  1393. if (classResult.status[index_stu] == 1)
  1394. {
  1395. if (!lostStu.Contains(classResult.studentIds[index_stu]))
  1396. {
  1397. lostStu.Add(classResult.studentIds[index_stu]);
  1398. }
  1399. }
  1400. }
  1401. index_stu++;
  1402. }
  1403. int index = 0;
  1404. foreach (List<double> scores in classResult.studentScores)
  1405. {
  1406. List<double> newScores = new List<double>();
  1407. //int count = 0;
  1408. if (scores.Count > 0)
  1409. {
  1410. foreach (double sc in scores)
  1411. {
  1412. newScores.Add(sc > -1 ? sc : 0);
  1413. }
  1414. }
  1415. else {
  1416. newScores.Add(0);
  1417. }
  1418. classSrate += newScores.Sum();
  1419. score += newScores.Sum();
  1420. result.studentScores.Add(newScores);
  1421. index++;
  1422. }
  1423. //处理班级信息
  1424. ClassRange range = new ClassRange();
  1425. range.id = classResult.info.id;
  1426. range.name = classResult.info.name;
  1427. range.gradeId = classResult.gradeId;
  1428. List<int> ran = new List<int>();
  1429. int stuCount = classResult.studentIds.Count;
  1430. //todo 与实际的缺考人数比较
  1431. int lostStus = classResult.status.Where(c => c == 1).ToList().Count;
  1432. Count += stuCount;
  1433. if (m == 0)
  1434. {
  1435. ran.Add(0);
  1436. ran.Add(stuCount - 1);
  1437. }
  1438. else
  1439. {
  1440. ran.Add(Count - stuCount);
  1441. ran.Add(Count - 1);
  1442. }
  1443. m++;
  1444. range.range = ran;
  1445. classRanges.Add(range);
  1446. //处理学生ID
  1447. foreach (string id in classResult.studentIds)
  1448. {
  1449. result.studentIds.Add(id);
  1450. }
  1451. if (allScore > 0)
  1452. {
  1453. csRate.Add(classResult.studentIds.Count - lostStus > 0 ? Math.Round(classSrate * 1.0 / (classResult.studentIds.Count - lostStus), 2) : 0 / allScore);
  1454. }
  1455. else
  1456. {
  1457. csRate.Add(0);
  1458. }
  1459. //powSum += Math.Pow(classSrate - result.average, 2);
  1460. //处理选项计数内容
  1461. }
  1462. //tasks.Add(_azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"{classResult.code}")));
  1463. }
  1464. //await tasks.TaskPage(10);
  1465. /*foreach (string id in result.lostStus) {
  1466. if (!examClassResults[0].studentIds.Contains(id)) {
  1467. int index = result.lostStus.IndexOf(id);
  1468. result.lostStus.RemoveAt(index);
  1469. }
  1470. }*/
  1471. //处理人员变更时被移除的人员
  1472. result.lostStus = lostStu;
  1473. List<string> stuIds = examClassResults.SelectMany(x => x.studentIds).ToList();
  1474. if (result.lostStus.Count > 0)
  1475. {
  1476. for (int i = 0; i < result.lostStus.Count; i++)
  1477. {
  1478. if (!stuIds.Contains(result.lostStus[i]))
  1479. {
  1480. result.lostStus.RemoveAt(i);
  1481. }
  1482. }
  1483. }
  1484. result.record = getMore(info, no, opt);
  1485. result.average = result.studentIds.Count - result.lostStus.Count > 0 ? Math.Round(score * 1.0 / (result.studentIds.Count - result.lostStus.Count), 2) : 0;
  1486. double powSum = 0;
  1487. //int sco = 0;
  1488. result.studentIds.ForEach(x =>
  1489. {
  1490. double sc = result.studentScores[result.studentIds.IndexOf(x)].Sum();
  1491. if (!result.lostStus.Contains(x))
  1492. {
  1493. powSum += Math.Pow(sc - result.average, 2);
  1494. }
  1495. });
  1496. result.standard = Math.Round((result.studentIds.Count - result.lostStus.Count) > 0 ? Math.Pow(powSum / (result.studentIds.Count - result.lostStus.Count), 0.5) : 0, 2);
  1497. result.csRate = csRate;
  1498. result.sRate = allScore > 0 ? Math.Round(result.average / allScore * 100, 2) : 0;
  1499. result.classes = classRanges;
  1500. result.code = "ExamResult-" + info.id;
  1501. result.school = info.school;
  1502. result.id = subject.id;
  1503. result.examId = info.id;
  1504. result.subjectId = subject.id;
  1505. result.year = info.year;
  1506. result.paper = info.papers[no];
  1507. //result.point = info.papers[j].point;
  1508. result.scope = info.scope;
  1509. result.name = info.name;
  1510. result.time = info.startTime;
  1511. await examRecordCount(info, subject, _dingDing, no, result, examClassResults, _azureCosmos);
  1512. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").UpsertItemAsync(result, new Azure.Cosmos.PartitionKey($"ExamResult-{info.id}"));
  1513. List<ErrorItems> errorItems = new();
  1514. string code = string.Empty;
  1515. string pk = string.Empty;
  1516. string table = "School";
  1517. if (info.scope.Equals("school"))
  1518. {
  1519. code = $"ErrorItems-{info.school}";
  1520. pk = $"Item-{info.school}";
  1521. }
  1522. else
  1523. {
  1524. code = "ErrorItems";
  1525. pk = $"Item-{info.creatorId}";
  1526. table = "Teacher";
  1527. }
  1528. string sqlqueryText = $"select value(c) from c where c.activityId = '{info.id}'and c.subjectId = '{info.subjects[no].id}' and c.stuId in ({string.Join(",", result.studentIds.Select(x => $"'{x}'"))})";
  1529. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<ErrorItems>(queryText: sqlqueryText, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
  1530. {
  1531. errorItems.Add(item);
  1532. }
  1533. try {
  1534. /* bool isError = examClassResults.SelectMany(c => c.status).ToList().Exists(z => z == 1);
  1535. if () {
  1536. }*/
  1537. if (errorItems.Count == 0 && info.qamode != 2)
  1538. {
  1539. // 新增逻辑 收集错题内容
  1540. BlobDownloadResult index_json;
  1541. if (info.scope.Equals("school"))
  1542. {
  1543. index_json = await _azureStorage.GetBlobContainerClient($"{info.school}").GetBlobClient($"{info.papers[no].blob}/index.json").DownloadContentAsync();
  1544. }
  1545. else
  1546. {
  1547. index_json = await _azureStorage.GetBlobContainerClient($"{info.creatorId}").GetBlobClient($"{info.papers[no].blob}/index.json").DownloadContentAsync();
  1548. }
  1549. //BlobDownloadResult index_json = await _azureStorage.GetBlobContainerClient($"{info.school}").GetBlobClient($"{info.papers[no].blob}/index.json").DownloadContentAsync();
  1550. //JObject jo = JObject.Parse(new MemoryStream(Encoding.UTF8.GetBytes(index_json.Content.ToString())).ToString());
  1551. JsonElement RecordingJson = JsonDocument.Parse(new MemoryStream(Encoding.UTF8.GetBytes(index_json.Content.ToString()))).RootElement;
  1552. RecordingJson.TryGetProperty("slides", out JsonElement slides);
  1553. var sdes = slides.ToObject<List<Slides>>();
  1554. List<string> attachments = new List<string>();
  1555. if (info.qamode == 1) {
  1556. attachments = RecordingJson.GetProperty("attachments").ToObject<List<string>>();
  1557. if (attachments.Count == 0)
  1558. {
  1559. return;
  1560. }
  1561. }
  1562. List<string> urls = new();
  1563. foreach (var ne in sdes)
  1564. {
  1565. if (!ne.type.Equals("compose"))
  1566. {
  1567. urls.Add(ne.url);
  1568. }
  1569. }
  1570. // 获取整体的题目ID集合
  1571. List<string> ids = new();
  1572. List<(string id, string pid, int level, string type, List<string> knows)> itemInfos = new();
  1573. foreach (string url in urls)
  1574. {
  1575. string id = url.Replace(".json", "");
  1576. BlobDownloadResult index_item_json;
  1577. if (info.scope.Equals("school"))
  1578. {
  1579. index_item_json = await _azureStorage.GetBlobContainerClient($"{info.school}").GetBlobClient($"{info.papers[no].blob}/{url}").DownloadContentAsync();
  1580. }
  1581. else
  1582. {
  1583. index_item_json = await _azureStorage.GetBlobContainerClient($"{info.creatorId}").GetBlobClient($"{info.papers[no].blob}/{url}").DownloadContentAsync();
  1584. }
  1585. JObject keys = JObject.Parse(index_item_json.Content.ToString());
  1586. string type = keys["exercise"].Value<string>("type");
  1587. int level = keys["exercise"].Value<int>("level");
  1588. var knowledge = keys["exercise"].Value<JArray>("knowledge")?.ToObject<List<string>>();
  1589. string pid = keys.Value<string>("pid");
  1590. itemInfos.Add((id, pid, level, type, knowledge));
  1591. }
  1592. /* double[] point = StringHelper.ListTodouble(result.paper.point);
  1593. double[,] res = StringHelper.ListToDouble(result.studentScores);
  1594. var cdm = new ClouDASMatrix(res, point);*/
  1595. //需要努力的题目
  1596. //var ss = cdm.StriveTopic;
  1597. int n = 0;
  1598. List<Task<ItemResponse<ErrorItems>>> task_error = new();
  1599. List<ErrorItems> errors = new();
  1600. foreach (var sIds in result.studentIds)
  1601. {
  1602. ErrorItems error = new()
  1603. {
  1604. ttl = -1,
  1605. code = code,
  1606. id = Guid.NewGuid().ToString(),
  1607. stuId = sIds,
  1608. school = info.school,
  1609. activityId = info.id,
  1610. subjectId = result.subjectId,
  1611. time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
  1612. };
  1613. int index_stu = result.studentIds.IndexOf(sIds);
  1614. //顺序学生错题的索引
  1615. var itemScore = result.studentScores[index_stu];
  1616. List<int> index = new();
  1617. int index_item = 0;
  1618. foreach (var sc in itemScore) {
  1619. if (sc == 0) {
  1620. index.Add(index_item+1);
  1621. }
  1622. index_item++;
  1623. }
  1624. if (index.Count == 0) {
  1625. continue;
  1626. }
  1627. //int[] item_index = ss[n];
  1628. foreach (var item in index)
  1629. {
  1630. Items items = new()
  1631. {
  1632. id = urls[item - 1].Replace(".json", ""),
  1633. blob = info.papers[no].blob
  1634. };
  1635. items.level = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().level;
  1636. items.type = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().type;
  1637. items.pId = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().pid;
  1638. items.knowledge = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().knows;
  1639. items.qamode = info.qamode;
  1640. error.its.Add(items);
  1641. }
  1642. errors.Add(error);
  1643. n++;
  1644. task_error.Add(_azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").CreateItemAsync(error, new PartitionKey($"{error.code}")));
  1645. }
  1646. //string connect = _configuration.GetValue<string>("HaBookAuth:Crtmabank") + "https://malearnfunction.chinacloudsites.cn/api/crtmabank";
  1647. string location = $"{Environment.GetEnvironmentVariable("Option:Location")}";
  1648. string urlAction = string.Empty;
  1649. string accessKey = string.Empty;
  1650. if (location.Contains("China"))
  1651. {
  1652. if(location.Equals("China")) //大陸正式站
  1653. {
  1654. urlAction = "https://malearn.teammodel.cn";
  1655. accessKey = "2BcXFR_hvzG1pZjqIkaM7Dx74Hcu6m0PwwOacFpDpq44AzFuHJBRXA==";
  1656. }
  1657. else if(location.Equals("China-Dep") || location.Equals("China-Test")) //大陸測試站
  1658. {
  1659. urlAction = "https://malearn-rc.teammodel.cn";
  1660. accessKey = "lghWhJduNiAlo-e8isqEoROjdR7DAC-50XNtanIwHKYlAzFu1aog_A==";
  1661. }
  1662. }
  1663. else if (location.Contains("Global"))
  1664. {
  1665. if(location.Equals("Global")) //國際正式站
  1666. {
  1667. urlAction = "https://malearn.teammodel.net";
  1668. accessKey = "I-2lTcdggJkZWSBwOXQIm4oHx-huwX3d0wLe-9pgojThAzFuq_KNFg==";
  1669. }
  1670. else if(location.Equals("Global-Test")) //國際測試站
  1671. {
  1672. urlAction = "https://malearn-rc.teammodel.net";
  1673. accessKey = "_l4Cb_tHIRBw_iv3ZuwVqjkMwjg4_HtDaxhAmZ8OwJraAzFu_DAY8A==";
  1674. }
  1675. }
  1676. string connect = $"{urlAction}/api/crtmabank";
  1677. var htc = _httpClient.CreateClient();
  1678. if (htc.DefaultRequestHeaders.Contains("x-functions-key"))
  1679. {
  1680. htc.DefaultRequestHeaders.Remove("x-functions-key");
  1681. }
  1682. htc.DefaultRequestHeaders.Add("x-functions-key", accessKey);
  1683. ///智慧題庫school欄位修正
  1684. foreach (ErrorItems error in errors)
  1685. {
  1686. error.school = (info.scope.Equals("school")) ? info.school : string.Empty;
  1687. }
  1688. string paramJson = JsonConvert.SerializeObject(errors);
  1689. var content = new StringContent(paramJson, Encoding.UTF8, "application/json");
  1690. var response = await htc.PostAsync(connect, content);
  1691. if ((int)response.StatusCode == 200) {
  1692. await task_error.TaskPage(10);
  1693. }
  1694. }
  1695. } catch (Exception e) {
  1696. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测错题异常{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1697. }
  1698. }
  1699. public class Settlement
  1700. {
  1701. public double rate { get; set; }
  1702. public double score { get; set; }
  1703. public List<string> stus { get; set; } = new List<string>();
  1704. public int total { get; set; }
  1705. public double qrate { get; set; }
  1706. }
  1707. public class Slides
  1708. {
  1709. public string url { get; set; }
  1710. public string type { get; set; }
  1711. public Scoring scoring { get; set; } = new Scoring();
  1712. }
  1713. public class Scoring
  1714. {
  1715. public double score { get; set; }
  1716. public List<string> knowledge { get; set; } = new List<string>();
  1717. public int field { get; set; } = new();
  1718. public List<string> ans { get; set; } = new List<string>();
  1719. }
  1720. }
  1721. }