TriggerExam.cs 122 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219
  1. using Microsoft.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 ClouDASLibx;
  9. using System.Text.Json;
  10. using System.Collections.Generic;
  11. using System.Threading.Tasks;
  12. using System;
  13. using System.Linq;
  14. using TEAMModelOS.SDK.Models.Service.BI;
  15. using Azure.Storage.Blobs.Models;
  16. using System.IO;
  17. using System.Text;
  18. using System.Text.Json.Nodes;
  19. using Newtonsoft.Json.Linq;
  20. using TEAMModelOS.SDK.Models.Cosmos.Student;
  21. using TEAMModelOS.Models.Dto;
  22. using TEAMModelOS.SDK.Models.Cosmos.Common;
  23. using System.Net.Http;
  24. using Newtonsoft.Json;
  25. using System.Net;
  26. using System.Security.Policy;
  27. using Microsoft.Extensions.Configuration;
  28. using Microsoft.Extensions.Options;
  29. using TEAMModelOS.Models;
  30. using Microsoft.AspNetCore.Razor.TagHelpers;
  31. using HtmlAgilityPack;
  32. using Azure.Storage.Blobs;
  33. using System.ComponentModel;
  34. using TEAMModelOS.Function;
  35. namespace TEAMModelOS.CosmosDBTriggers
  36. {
  37. public class TriggerExam
  38. {
  39. public static async Task Trigger(CoreAPIHttpService _coreAPIHttpService, AzureCosmosFactory _azureCosmos, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, DingDing _dingDing,
  40. CosmosClient client, JsonElement input, TriggerData data, IHttpClientFactory _httpClient, IConfiguration _configuration, HttpTrigger _httpTrigger,AzureRedisFactory _azureRedis)
  41. {
  42. List<ExamClassResult> examClassResults = new();
  43. List<ExamSubject> examSubjects = new();
  44. try
  45. {
  46. if ((data.status != null && data.status.Value == 404))
  47. {
  48. await client.GetContainer(Constant.TEAMModelOS, "Common").DeleteItemStreamAsync(data.id, new PartitionKey(data.code));
  49. ActivityList activity = input.ToObject<ActivityList>();
  50. //await IESActivityService.DeleteActivity(_coreAPIHttpService, client, _dingDing, activity);
  51. var table_cancel = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
  52. List<ChangeRecord> records = await table_cancel.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", data.id } });
  53. foreach (var record in records)
  54. {
  55. try
  56. {
  57. await table_cancel.DeleteSingle<ChangeRecord>(record.PartitionKey, record.RowKey);
  58. await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), record.sequenceNumber);
  59. }
  60. catch (Exception)
  61. {
  62. continue;
  63. }
  64. }
  65. await BIStats.SetTypeAddStats(client, _dingDing, data.school, "Exam", -1, careDate: data.startTime);//BI统计增/减量
  66. return;
  67. }
  68. ExamInfo info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(data.id, new PartitionKey($"{data.code}"));
  69. if (info != null)
  70. {
  71. if (info.scope.Equals("teacher", StringComparison.OrdinalIgnoreCase) || info.scope.Equals("private", StringComparison.OrdinalIgnoreCase))
  72. {
  73. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIteratorSql(queryText: $"select value(c) from c where c.examId = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{info.creatorId}") }))
  74. {
  75. using var json = await JsonDocument.ParseAsync(item.Content);
  76. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  77. {
  78. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  79. {
  80. examClassResults.Add(obj.ToObject<ExamClassResult>());
  81. }
  82. }
  83. }
  84. }
  85. else
  86. {
  87. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIteratorSql(queryText: $"select value(c) from c where c.examId = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{data.school}") }))
  88. {
  89. using var json = await JsonDocument.ParseAsync(item.Content);
  90. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  91. {
  92. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  93. {
  94. examClassResults.Add(obj.ToObject<ExamClassResult>());
  95. }
  96. }
  97. }
  98. }
  99. var table = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
  100. string PartitionKey = string.Format("{0}{1}{2}", info.code, "-", info.progress);
  101. List<ChangeRecord> records = await table.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", data.id }, { "PartitionKey", PartitionKey } });
  102. //处理科目信息
  103. List<string> sub = new List<string>();
  104. School sc = new();
  105. if (!string.IsNullOrEmpty(info.school) && !info.school.Equals("SYSTEM_NO_SCHOOL"))
  106. {
  107. sc = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(info.school, new PartitionKey("Base"));
  108. }
  109. foreach (ExamSubject subject in info.subjects)
  110. {
  111. sub.Add(subject.id);
  112. }
  113. //整合名单
  114. List<string> classes = ExamService.getClasses(info.classes, info.stuLists);
  115. //ChangeRecord record = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ChangeRecord>(input.Id, new PartitionKey($"{info.progress}"));
  116. switch (info.progress)
  117. {
  118. case "pending":
  119. var message = new ServiceBusMessage(new { id = data.id, progress = "going", code = data.code }.ToJsonString());
  120. message.ApplicationProperties.Add("name", "Exam");
  121. if (records.Count > 0)
  122. {
  123. try
  124. {
  125. await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), records[0].sequenceNumber);
  126. }
  127. catch (Exception)
  128. {
  129. }
  130. long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), message, DateTimeOffset.FromUnixTimeMilliseconds(data.startTime));
  131. records[0].sequenceNumber = start;
  132. await table.SaveOrUpdate<ChangeRecord>(records[0]);
  133. //await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(record, record.id, new PartitionKey($"{record.code}"));
  134. }
  135. else
  136. {
  137. long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), message, DateTimeOffset.FromUnixTimeMilliseconds(data.startTime));
  138. //string pk = String.Format("{0}{1}{2}", info.code, "-", "pending");
  139. ChangeRecord changeRecord = new ChangeRecord
  140. {
  141. RowKey = data.id,
  142. PartitionKey = PartitionKey,
  143. sequenceNumber = start,
  144. msgId = message.MessageId
  145. };
  146. await table.Save<ChangeRecord>(changeRecord);
  147. //await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(changeRecord, new PartitionKey($"{changeRecord.code}"));
  148. }
  149. break;
  150. case "going":
  151. try
  152. {
  153. //向学生或醍摩豆账号发起通知
  154. #region
  155. //Notice notice = new Notice()
  156. //{
  157. // msgId = info.id,
  158. // creation = info.startTime,
  159. // expire = info.endTime,
  160. // creatorId = info.creatorId,
  161. // stuids = studentss,
  162. // tmdids = tmdids,
  163. // type = "notice",//评测参加通知
  164. // priority = "normal",
  165. // school = info.school,
  166. // scope = info.scope,
  167. // //data = new { }.ToJsonString()
  168. // body = new Body { sid = info.id, scode = info.code, spk = info.pk, biztype = "exam-join" }
  169. //};
  170. //var messageBlob = new ServiceBusMessage(notice.ToJsonString());
  171. //messageBlob.ApplicationProperties.Add("name", "Notice");
  172. //await _serviceBus.GetServiceBusClient().SendMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageBlob);
  173. #endregion
  174. //List<string> classes = new List<string>();
  175. if (info!=null && info.scope.Equals("private"))
  176. {
  177. await SystemService.RecordAccumulateData(_azureRedis, _dingDing, new SDK.Models.Dtos.Accumulate { client="web", count=1, id=info.id, key="exam-going", name=info.name, scope="teacher", target=info.creatorId });
  178. }
  179. //处理活动中间件
  180. List<RGroupList> members = await Activity(_coreAPIHttpService, info, classes, client, _dingDing, sub, examClassResults);
  181. if (examClassResults.Count == 0)
  182. {
  183. List<Task<ItemResponse<ExamClassResult>>> tasks = new List<Task<ItemResponse<ExamClassResult>>>();
  184. foreach (string cla in classes)
  185. {
  186. int m = 0;
  187. RGroupList rGroup = new();
  188. rGroup = members.Where(m => m.id.Equals(cla)).FirstOrDefault();
  189. foreach (ExamSubject subject in info.subjects)
  190. {
  191. string classCode = string.Empty;
  192. string? cname = string.Empty;
  193. if (string.IsNullOrEmpty(info.school) || !info.scope.Equals("school", StringComparison.OrdinalIgnoreCase))
  194. {
  195. classCode = "ExamClassResult-" + info.creatorId;
  196. }
  197. else
  198. {
  199. classCode = "ExamClassResult-" + info.school;
  200. }
  201. cname = members.Where(m => m.id.Equals(cla)).FirstOrDefault()?.name;
  202. // 预处理活动中间件信息
  203. ExamClassResult result = new()
  204. {
  205. code = classCode,
  206. examId = info.id,
  207. id = Guid.NewGuid().ToString(),
  208. subjectId = subject.id,
  209. year = info.year,
  210. scope = info.scope
  211. };
  212. result.info.id = cla;
  213. result.info.name = cname;
  214. List<string> ans = new();
  215. List<List<string>> anses = new();
  216. List<List<Details>> marks = new();
  217. List<double> ansPoint = new();
  218. List<(string sId, string scode)> ids = new();
  219. foreach (double p in info.papers[m].point)
  220. {
  221. //Details details = new Details();
  222. //ans.Add(new List<string>());
  223. anses.Add(new List<string>());
  224. marks.Add(new List<Details>());
  225. ansPoint.Add(-1);
  226. }
  227. var sresponse = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(cla, new PartitionKey($"Class-{info.school}"));
  228. if (sresponse.StatusCode == System.Net.HttpStatusCode.OK)
  229. {
  230. using var json = await JsonDocument.ParseAsync(sresponse.Content);
  231. Class classroom = json.ToObject<Class>();
  232. foreach (SDK.Models.Period period in sc.period)
  233. {
  234. if (period.id.Equals(classroom.periodId))
  235. {
  236. foreach (Semester semester in period.semesters)
  237. {
  238. if (semester.start == 1)
  239. {
  240. int year = DateTimeOffset.UtcNow.Year;
  241. int month = DateTimeOffset.UtcNow.Month;
  242. int day = DateTimeOffset.UtcNow.Day;
  243. int time = 0;
  244. if (month == semester.month)
  245. {
  246. time = day >= semester.day ? 0 : 1;
  247. }
  248. else
  249. {
  250. time = month > semester.month ? 0 : 1;
  251. }
  252. int eyear = year - time;
  253. result.gradeId = (eyear - classroom.year).ToString();
  254. }
  255. }
  256. }
  257. }
  258. //result.info.id = classroom.id;
  259. //result.info.name = classroom.name;
  260. //result.gradeId = classroom.year.ToString();
  261. //处理班级人数
  262. /* await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIteratorSql(queryText: $"select c.id from c where c.classId = '{classroom.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{info.school}") }))
  263. {
  264. using var json_stu = await JsonDocument.ParseAsync(item.Content);
  265. if (json_stu.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  266. {
  267. var accounts = json_stu.RootElement.GetProperty("Documents").EnumerateArray();
  268. while (accounts.MoveNext())
  269. {
  270. JsonElement account = accounts.Current;
  271. ids.Add(account.GetProperty("id").GetString());
  272. }
  273. }
  274. }*/
  275. }
  276. /*if (info.scope.Equals("private", StringComparison.OrdinalIgnoreCase))
  277. {
  278. var stuResponse = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemStreamAsync(cla, new PartitionKey($"GroupList"));
  279. if (stuResponse.Status == 200)
  280. {
  281. using var json = await JsonDocument.ParseAsync(stuResponse.Content);
  282. GroupList stuList = json.ToObject<GroupList>();
  283. //result.info.id = stuList.id;
  284. result.info.name = stuList.name;
  285. //处理发布对象为自选名单(个人)
  286. foreach (Member stus in stuList.members)
  287. {
  288. if (!ids.Contains(stus.id))
  289. {
  290. ids.Add(stus.id);
  291. }
  292. }
  293. }
  294. }
  295. else
  296. {
  297. var stuResponse = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(cla, new PartitionKey($"GroupList-{info.school}"));
  298. if (stuResponse.Status == 200)
  299. {
  300. using var json = await JsonDocument.ParseAsync(stuResponse.Content);
  301. GroupList stuList = json.ToObject<GroupList>();
  302. //result.info.id = stuList.id;
  303. result.info.name = stuList.name;
  304. //处理发布对象为自选名单(校本)
  305. foreach (Member stus in stuList.members)
  306. {
  307. if (!ids.Contains(stus.id))
  308. {
  309. ids.Add(stus.id);
  310. }
  311. }
  312. }
  313. }*/
  314. foreach (RMember member in rGroup.members)
  315. {
  316. ids.Add((member.id, member.code));
  317. }
  318. //ids = members.Where(c => c.id.Equals(cla)).SelectMany(m => m.members).Select(g => g.id).ToList();
  319. List<string> blobs = new();
  320. if (info.qamode == 2) {
  321. blobs = info.papers.Where(c => c.subjectId.Equals(subject.id)).Select(c => c.blob).ToList();
  322. }
  323. foreach (var (sId, scode) in ids)
  324. {
  325. result.mark.Add(marks);
  326. result.studentIds.Add(sId);
  327. //result.scIds.Add(scode ?? "");
  328. result.studentAnswers.Add(ans);
  329. result.studentScores.Add(ansPoint);
  330. result.ans.Add(anses);
  331. result.sum.Add(0);
  332. result.status.Add(1);
  333. if (info.qamode == 2) {
  334. result.paper.Add(blobs[new Random().Next(blobs.Count)]);
  335. }
  336. }
  337. //result.progress = info.progress;
  338. result.school = info.school;
  339. m++;
  340. tasks.Add(client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(result, new PartitionKey($"{result.code}")));
  341. }
  342. }
  343. await tasks.TaskPage(10);
  344. }
  345. else
  346. {
  347. //处理单科结算时科目与试卷信息匹配的问题
  348. int gno = 0;
  349. foreach (ExamSubject subject in info.subjects)
  350. {
  351. if (subject.classCount == classes.Count)
  352. {
  353. await createClassResultAsync(info, examClassResults, subject, gno, _azureCosmos, _dingDing, _azureStorage, _httpClient, _configuration);
  354. }
  355. gno++;
  356. }
  357. var isScore = examClassResults.SelectMany(e => e.studentScores).ToList().Exists(c => c.Contains(-1));
  358. int newStatus = 0;
  359. if (!isScore)
  360. {
  361. newStatus = 1;
  362. }
  363. Settlement settlement = await getMore(client, info);
  364. long nowTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  365. //判断评分状态是否发生变化,便于实时的更新评测基本信息
  366. if (info.average != settlement.score || info.sStatus != newStatus)
  367. {
  368. info.sRate = settlement.rate;
  369. info.sStatus = newStatus;
  370. info.updateTime = nowTime;
  371. info.average = settlement.score;
  372. await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ExamInfo>(info, info.id, new PartitionKey(info.code));
  373. }
  374. }
  375. }
  376. catch (Exception e)
  377. {
  378. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测going状态异常{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  379. }
  380. finally
  381. {
  382. try {
  383. //新增serviceBus 消息释放后处理table
  384. string pkey = string.Format("{0}{1}{2}", info.code, "-", "pending");
  385. await table.DeleteSingle<ChangeRecord>(pkey, data.id);
  386. // 发送信息通知
  387. var messageEnd = new ServiceBusMessage(new { id = data.id, progress = "finish", code = data.code }.ToJsonString());
  388. messageEnd.ApplicationProperties.Add("name", "Exam");
  389. if (records.Count > 0)
  390. {
  391. long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageEnd, DateTimeOffset.FromUnixTimeMilliseconds(data.endTime));
  392. await _serviceBus.GetServiceBusClient().CancelMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), records[0].sequenceNumber);
  393. records[0].sequenceNumber = end;
  394. await table.SaveOrUpdate<ChangeRecord>(records[0]);
  395. //await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(record, record.id, new PartitionKey($"{record.code}"));
  396. }
  397. else
  398. {
  399. long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageEnd, DateTimeOffset.FromUnixTimeMilliseconds(data.endTime));
  400. //string pk = String.Format("{0}{1}{2}", info.code, "-", "going");
  401. ChangeRecord changeRecord = new ChangeRecord
  402. {
  403. RowKey = data.id,
  404. PartitionKey = PartitionKey,
  405. sequenceNumber = end,
  406. msgId = messageEnd.MessageId
  407. };
  408. await table.Save<ChangeRecord>(changeRecord);
  409. //await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(changeRecord, new PartitionKey($"{changeRecord.code}"));
  410. }
  411. } catch (Exception e) {
  412. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-ChangeRecord{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  413. }
  414. }
  415. break;
  416. case "finish":
  417. int fno = 0;
  418. try
  419. {
  420. //await SetLearnRecordContent(info, data, _azureStorage, _azureCosmos);
  421. //用来判定是否完成评分
  422. //bool isScore = true;
  423. await resultStatus(client, examClassResults);
  424. await Activity(_coreAPIHttpService, info, classes, client, _dingDing, sub, examClassResults);
  425. foreach (ExamSubject subject in info.subjects)
  426. {
  427. await createClassResultAsync(info, examClassResults, subject, fno, _azureCosmos, _dingDing, _azureStorage, _httpClient, _configuration);
  428. fno++;
  429. }
  430. Settlement settlement = await getMore(client, info);
  431. var isScore = examClassResults.SelectMany(e => e.studentScores).ToList().Exists(c => c.Contains(-1));
  432. int newStatus = 0;
  433. if (!isScore)
  434. {
  435. newStatus = 1;
  436. }
  437. //判断均分是否发生变化,便于实时的更新评测基本信息
  438. if (info.sRate != settlement.rate || info.average != settlement.score || info.sStatus != newStatus || info.qRate != settlement.qrate)
  439. {
  440. info.sRate = settlement.rate;
  441. info.average = settlement.score;
  442. info.sStatus = newStatus;
  443. info.lostStu = settlement.stus;
  444. info.stuCount = settlement.total;
  445. info.qRate = settlement.qrate;
  446. //新增数据推送 obj => Portrait
  447. Portrait portrait = new()
  448. {
  449. schoolCode = info.school,
  450. periodId = info.period.id,
  451. subjectId = "subject_intelligence"
  452. };
  453. //作答合格率
  454. var sta = examClassResults.SelectMany(x => x.status).ToList();
  455. /* var stus = examClassResults.SelectMany(x => x.studentIds).ToList();
  456. var stuScores = examClassResults.SelectMany(x => x.studentScores).ToList();*/
  457. var ansCount = sta.Where(x => x == 0).ToList();
  458. var persent = ansCount.Count * 1.0 / sta.Count * 100;
  459. var period = sc.period.Where(x => x.id.Equals(info.period.id)).FirstOrDefault();
  460. List<string> subjects = info.subjects.Select(x => x.id).ToList();
  461. //获取学期信息
  462. if (null != period && persent >= 60 && !subjects.Contains("subject_painting") && !subjects.Contains("subject_music"))
  463. {
  464. var (currSemester, studyYear, currSemesterDate, date, nextSemester) = SchoolService.GetSemester(period, info.startTime);
  465. //获取学生信息
  466. (List<RMember> rmembers, List<RGroupList> groups) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, info.classes, info.school);
  467. foreach (var member in rmembers)
  468. {
  469. if (info.lostStu.Contains(member.id))
  470. {
  471. continue;
  472. }
  473. PortraitStudent student = new()
  474. {
  475. studentId = member.id,
  476. name = member.name,
  477. classId = member.classId
  478. };
  479. var ec = examClassResults.Where(c => c.studentIds.Contains(member.id)).ToList();
  480. double scores = 0;
  481. List<(string subjectId, double score)> subScore = new();
  482. foreach (var eclass in ec)
  483. {
  484. int index_stu = eclass.studentIds.IndexOf(member.id);
  485. scores += eclass.sum[index_stu];
  486. subScore.Add((eclass.subjectId, eclass.sum[index_stu]));
  487. }
  488. SemesterData semesterData = new()
  489. {
  490. examName = info.name,
  491. examId = info.id,
  492. examDate = info.startTime,
  493. examType = info.examType?.name,
  494. year = info.year,
  495. semesterId = currSemester.id,
  496. totalScore = info.papers.SelectMany(x => x.point).Sum(),
  497. sumScore = scores,
  498. excellenceRate = 0,
  499. passRate = 0,
  500. };
  501. int index = 0;
  502. foreach (var sj in info.subjects)
  503. {
  504. ItemScore item = new()
  505. {
  506. id = sj.id,
  507. name = sj.name,
  508. score = subScore.Where(c => c.subjectId.Equals(sj.id)).FirstOrDefault().score,
  509. time = info.startTime,
  510. totalScore = info.papers[index].point.Sum(),
  511. type = sj.id
  512. };
  513. index++;
  514. semesterData.itemScore.Add(item);
  515. }
  516. student.semesterData.Add(semesterData);
  517. portrait.students.Add(student);
  518. }
  519. string location = $"{Environment.GetEnvironmentVariable("Option:Location")}";
  520. var (status, json) = await _httpTrigger.RequestHttpTrigger(portrait, location, "upsert-student-portrait");
  521. }
  522. //PortraitStudent student = new();
  523. //处理试卷活动结束统计账户信息
  524. List<FMember> idList = await GroupListService.GetFinishMemberInfo(_coreAPIHttpService, client, _dingDing, info.school, info.classes, info.stuLists, null);
  525. info.staffIds = idList;
  526. await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ExamInfo>(info, info.id, new PartitionKey(info.code));
  527. }
  528. await SetLearnRecordContent(info, data, _azureStorage, _azureCosmos);
  529. }
  530. catch (Exception e)
  531. {
  532. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测finish状态异常{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  533. }
  534. finally {
  535. //新增serviceBus 消息释放后处理table
  536. string pk = string.Format("{0}{1}{2}", info.code, "-", "going");
  537. await table.DeleteSingle<ChangeRecord>(pk, data.id);
  538. }
  539. break;
  540. }
  541. }
  542. }
  543. catch (CosmosException e)
  544. {
  545. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-CosmosDB异常{e.Message}\n{e.StackTrace}\n{e.StatusCode}", GroupNames.醍摩豆服務運維群組);
  546. }
  547. catch (Exception e)
  548. {
  549. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-评测结算异常{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  550. }
  551. }
  552. private static async Task SetLearnRecordContent(ExamInfo info, TriggerData data, AzureStorageFactory _azureStorage, AzureCosmosFactory _azureCosmos)
  553. {
  554. try
  555. {
  556. if (info.papers.Count > 0)
  557. {
  558. for (int i = 0; i < info.papers.Count; i++)
  559. {// 每一個科目的試卷
  560. string rootName = "";
  561. //if (info.school == "SYSTEM_NO_SCHOOL")
  562. if (info.scope == "private")
  563. {// 未入校老師的評量
  564. rootName = info.creatorId;
  565. }
  566. else
  567. {// 如果有學校代碼
  568. rootName = info.school;
  569. }
  570. if (_azureStorage.GetBlobContainerClient(rootName).GetBlobClient($"{info.papers[i].blob}/index.json").Exists())
  571. {// 如果試卷的blob存在,再開始
  572. BlobDownloadResult paperblobDownload = await _azureStorage.GetBlobContainerClient(rootName).GetBlobClient($"{info.papers[i].blob}/index.json").DownloadContentAsync();
  573. PaperIndex paperIndex = paperblobDownload.Content.ToObjectFromJson<PaperIndex>();
  574. List<LearnRecordItem> learnRecordItems = new();
  575. StringBuilder sbsql = new StringBuilder($" SELECT * FROM c WHERE c.examId = '{info.id}' and c.pk = 'ExamClassResult' and c.subjectId = '{info.subjects[i].id}' ");
  576. #region === 開始拼裝資料 ===
  577. if (info.classes.Count > 0 || info.stuLists.Count > 0)
  578. {
  579. // 組合SQL
  580. if (info.classes.Count > 0)
  581. {// 按照classes取ans.json
  582. sbsql.Append($" and ARRAY_CONTAINS({System.Text.Json.JsonSerializer.Serialize(info.classes)}, c.info.id)");
  583. }
  584. else if (info.stuLists.Count > 0)
  585. {
  586. sbsql.Append($" and ARRAY_CONTAINS({System.Text.Json.JsonSerializer.Serialize(info.stuLists)}, c.info.id)");
  587. }
  588. // 取學生答案及學生名單
  589. var client = _azureCosmos.GetCosmosClient();
  590. Dictionary<string, List<string>> stuDic = new Dictionary<string, List<string>>();
  591. if (!string.IsNullOrWhiteSpace(info.school) && !stuDic.ContainsKey(info.school))
  592. {
  593. stuDic.Add(info.school, new List<string>());
  594. }
  595. List<StudentAnswers> studentAnswersList = new List<StudentAnswers>();
  596. List<string> stuListForSql = new List<string>();
  597. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Common).GetItemQueryIteratorSql<StudentAnswers>(queryText: sbsql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamClassResult-{rootName}") }))
  598. {
  599. studentAnswersList.Add(item);
  600. stuListForSql = stuListForSql.Union(item.studentIds).ToList();
  601. }
  602. //取得學校的學生名單
  603. List<string> stuOpenIdList = new List<string>();
  604. if(!string.IsNullOrWhiteSpace(info.school))
  605. {
  606. StringBuilder stusql = new StringBuilder($"SELECT VALUE c.id FROM c WHERE c.pk = 'Base' AND ARRAY_CONTAINS({System.Text.Json.JsonSerializer.Serialize(stuListForSql)}, c.id)");
  607. await foreach (string item in client.GetContainer(Constant.TEAMModelOS, Constant.Student).GetItemQueryIteratorSql<string>(queryText: stusql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{info.school}") }))
  608. {
  609. stuDic[info.school].Add(item);
  610. }
  611. }
  612. // 按照取出的學生答案blob 對答案 組合資料
  613. foreach (var studentAnswers in studentAnswersList)
  614. {// 每一個班級
  615. foreach (var studentAnswersBlob in studentAnswers.studentAnswers)
  616. {// 每一個學生
  617. if (studentAnswersBlob.Count > 0)
  618. {// 有學生的答案才開始
  619. if (_azureStorage.GetBlobContainerClient(rootName).GetBlobClient($"/exam/{studentAnswersBlob[0]}").Exists())
  620. {// 如果blob存在才開始
  621. BlobDownloadResult ansblobDownload = await _azureStorage.GetBlobContainerClient(rootName).GetBlobClient($"/exam/{studentAnswersBlob[0]}").DownloadContentAsync();
  622. List<List<string>> ansList = JsonConvert.DeserializeObject<List<List<string>>>(ansblobDownload.Content.ToString());
  623. // 從blob路徑取出學生id
  624. string[] arr = studentAnswersBlob[0].Split('/');
  625. string stuid = arr[arr.Length - 2];
  626. #region ===StartExam 開始課堂===
  627. LearnRecordItem LRItem_StartExam = new();
  628. LRItem_StartExam.verb = "StartExam";
  629. LRItem_StartExam.actor = getStuId(info.school, stuid, stuDic);
  630. LRItem_StartExam.time = info.createTime;
  631. LRItem_StartExam.ID = info.id;
  632. LRItem_StartExam.Desc = info.name;
  633. LRItem_StartExam.Correct = null;
  634. LRItem_StartExam.Choices = null;
  635. LRItem_StartExam.ExamQuesQty = info.papers[i].point.Count;
  636. LRItem_StartExam.TotalScore = 0;
  637. foreach (var pointItem in info.papers[i].point)
  638. {
  639. LRItem_StartExam.TotalScore = LRItem_StartExam.TotalScore + pointItem;
  640. }
  641. LRItem_StartExam.Success = null;
  642. learnRecordItems.Add(LRItem_StartExam);
  643. #endregion
  644. #region ===評量題目===
  645. for (int j = 0; j < ansList.Count; j++)
  646. {
  647. #region === 判斷題型 ===
  648. // 這五種題型才記錄
  649. if (paperIndex.slides[j].type == "single" ||
  650. paperIndex.slides[j].type == "multiple" ||
  651. paperIndex.slides[j].type == "judge" ||
  652. paperIndex.slides[j].type == "complete" ||
  653. paperIndex.slides[j].type == "subjective")
  654. {
  655. LearnRecordItem learnRecordItem = new();
  656. // 單選
  657. if (paperIndex.slides[j].type == "single") { learnRecordItem.verb = "AnsSingle"; }
  658. // 複選
  659. if (paperIndex.slides[j].type == "multiple") { learnRecordItem.verb = "AnsMultiple"; }
  660. // 是非
  661. if (paperIndex.slides[j].type == "judge") { learnRecordItem.verb = "AnsJudge"; }
  662. // 填充
  663. if (paperIndex.slides[j].type == "complete") { learnRecordItem.verb = "AnsComplete"; }
  664. // 問答
  665. if (paperIndex.slides[j].type == "subjective") { learnRecordItem.verb = "AnsSubjective"; }
  666. learnRecordItem.actor = getStuId(info.school, stuid, stuDic);
  667. learnRecordItem.time = data.endTime;
  668. string[] arrurlsingle = paperIndex.slides[j].url.Split('.');
  669. learnRecordItem.ID = arrurlsingle[0];
  670. #region === 設定Correct Choices Desc===
  671. if (_azureStorage.GetBlobContainerClient(rootName).GetBlobClient($"{info.papers[i].blob}/{paperIndex.slides[j].url}").Exists())
  672. {
  673. BlobDownloadResult itemblobDownload = await _azureStorage.GetBlobContainerClient(rootName).GetBlobClient($"{info.papers[i].blob}/{paperIndex.slides[j].url}").DownloadContentAsync();
  674. QuestionData questionData = itemblobDownload.Content.ToObjectFromJson<QuestionData>();
  675. setCorrectChoices(questionData, learnRecordItem);
  676. // 使用HtmlAgilityPack解析HTML
  677. HtmlDocument doc = new HtmlDocument();
  678. doc.LoadHtml(questionData.item[0].question);
  679. // 先刪除所有<img>標籤
  680. foreach (var imgNode in doc.DocumentNode.Descendants("img").ToArray())
  681. {
  682. imgNode.Remove();
  683. }
  684. // 再取純文字
  685. learnRecordItem.Desc = doc.DocumentNode.InnerText;
  686. }
  687. #endregion
  688. learnRecordItem.ExamQuesQty = null;
  689. learnRecordItem.TotalScore = null;
  690. learnRecordItem.Points = paperIndex.slides[j].scoring == null ? new List<string>() : paperIndex.slides[j].scoring.knowledge;
  691. //比對答案
  692. learnRecordItem.Success = paperIndex.slides[j].scoring == null ? null : (paperIndex.slides[j].scoring.ans.SequenceEqual(ansList[j]) ? true : false);
  693. learnRecordItems.Add(learnRecordItem);
  694. }
  695. #endregion
  696. }
  697. #endregion
  698. #region ===EndExam 結束課堂===
  699. LearnRecordItem LRItem_EndExam = new();
  700. LRItem_EndExam.verb = "EndExam";
  701. LRItem_EndExam.actor = getStuId(info.school, stuid, stuDic);
  702. LRItem_EndExam.time = info.endTime;
  703. LRItem_EndExam.ID = info.id;
  704. LRItem_EndExam.Desc = info.name;
  705. LRItem_EndExam.Correct = null;
  706. LRItem_EndExam.Choices = null;
  707. LRItem_EndExam.ExamQuesQty = info.papers[i].point.Count;
  708. LRItem_EndExam.TotalScore = 0;
  709. foreach (var pointItem in info.papers[i].point)
  710. {
  711. LRItem_EndExam.TotalScore = LRItem_EndExam.TotalScore + pointItem;
  712. }
  713. LRItem_EndExam.Success = null;
  714. learnRecordItems.Add(LRItem_EndExam);
  715. #endregion
  716. }
  717. }
  718. }
  719. }
  720. }
  721. #endregion
  722. if (learnRecordItems.Count > 0)
  723. {
  724. #region 寫入blob
  725. // 容器名称
  726. string containerName = "twmoeld";
  727. // 新文件的名称
  728. string blobName = $"/{DateTime.Now.ToString("yyyyMMdd")}/{info.id}.json";
  729. // 要上传的文件内容
  730. string fileContent = Newtonsoft.Json.JsonConvert.SerializeObject(learnRecordItems);
  731. // 获取容器引用
  732. BlobContainerClient containerClient = _azureStorage.GetBlobContainerClient(containerName);
  733. // 获取 Blob 客户端
  734. BlobClient blobClient = containerClient.GetBlobClient(blobName);
  735. // 将文件内容上传到 Blob
  736. using (MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(fileContent)))
  737. {
  738. await blobClient.UploadAsync(stream, true);
  739. }
  740. #endregion
  741. }
  742. }
  743. }
  744. }
  745. }
  746. catch (Exception ex)
  747. {
  748. }
  749. }
  750. /// <summary>
  751. /// 取得學習紀錄的actor
  752. /// </summary>
  753. /// <param name="learnRecordItem"></param>
  754. /// <param name="school"></param>
  755. /// <param name="stuid"></param>
  756. /// <returns></returns>
  757. private static string getStuId(string school, string stuid, Dictionary<string, List<string>> stuDic)
  758. {
  759. if (!string.IsNullOrWhiteSpace(school) && stuDic.ContainsKey(school) && stuDic[school].Contains(stuid))
  760. {// 校內帳號用組合的 "Base-hbgl,473891247381"
  761. return $"Base-{school.Trim()},{stuid}";
  762. }
  763. else
  764. {// 未入校老師的評量
  765. return stuid;
  766. }
  767. }
  768. private static void setCorrectChoices(QuestionData questionData, LearnRecordItem learnRecordItem)
  769. {
  770. #region === Correct Choices ===
  771. #region === 是非題邏輯 ===
  772. if (questionData.exercise.type == "judge" && questionData.exercise.answer.Count > 0)
  773. {// 如果是是非題 正確答案要用true false的方式設定
  774. if (questionData.exercise.answer[0] == "A")
  775. {
  776. learnRecordItem.Correct = new string[] { "true" };
  777. }
  778. else
  779. {
  780. learnRecordItem.Correct = new string[] { "false" };
  781. }
  782. }
  783. else
  784. {// 防呆 去html標籤
  785. if (questionData.exercise.answer.Count > 0)
  786. {
  787. List<string> anslist = new();
  788. foreach (var answer in questionData.exercise.answer)
  789. {
  790. // 使用HtmlAgilityPack解析HTML
  791. HtmlDocument doc = new HtmlDocument();
  792. doc.LoadHtml(answer);
  793. // 再取純文字
  794. anslist.Add(doc.DocumentNode.InnerText);
  795. }
  796. learnRecordItem.Correct = anslist;
  797. }
  798. else
  799. {
  800. learnRecordItem.Correct = questionData.exercise.answer;
  801. }
  802. }
  803. #endregion
  804. if (questionData.item[0].option.Count > 0)
  805. {// 如果有選項資料 記錄起來
  806. foreach (var option in questionData.item[0].option)
  807. {
  808. ChoicesItem item = new();
  809. item.id = option.code;
  810. if (questionData.exercise.type == "judge")
  811. {// 如果是是非題 固定選項
  812. if (option.code == "A")
  813. {
  814. item.description.zhTW = "是";
  815. }
  816. else
  817. {
  818. item.description.zhTW = "否";
  819. }
  820. }
  821. else
  822. {
  823. if (string.IsNullOrWhiteSpace(option.value))
  824. {
  825. item.description.zhTW = $"選項{option.code}";
  826. }
  827. else
  828. {
  829. // 使用HtmlAgilityPack解析HTML
  830. HtmlDocument doc = new HtmlDocument();
  831. doc.LoadHtml(option.value);
  832. // 再取純文字
  833. item.description.zhTW = doc.DocumentNode.InnerText;
  834. }
  835. }
  836. learnRecordItem.Choices.Add(item);
  837. }
  838. }
  839. #endregion
  840. }
  841. public static async Task resultStatus(CosmosClient client, List<ExamClassResult> examClassResults)
  842. {
  843. List<Task<ItemResponse<ExamClassResult>>> tasks = new();
  844. //结算单科单班的标准差和平均分
  845. foreach (ExamClassResult classResult in examClassResults)
  846. {
  847. //标记单科单班总得分
  848. double subScore = 0;
  849. //标准差
  850. double sPowSum = 0;
  851. List<double> newSumScore = new List<double>();
  852. List<double> effectiveScore = new List<double>();
  853. int lostStu = classResult.status.Where(c => c == 1).ToList().Count;
  854. var scount = classResult.studentIds.Count - lostStu;
  855. int index = 0;
  856. if (classResult.status.Count > 0)
  857. {
  858. foreach (var sta in classResult.status)
  859. {
  860. if (sta == 1)
  861. {
  862. for (int i = 0; i < classResult.studentScores[index].Count; i++)
  863. {
  864. if (classResult.studentScores[index][i] == -1)
  865. {
  866. classResult.studentScores[index][i] = 0;
  867. }
  868. }
  869. }
  870. else if (sta == 0)
  871. {
  872. //var ans = classResult.studentAnswers[index];
  873. //该学生缺考,历史数据的判定
  874. //if (ans.Count == 0)
  875. //{
  876. for (int i = 0; i < classResult.studentScores[index].Count; i++)
  877. {
  878. if (classResult.studentScores[index][i] == -1)
  879. {
  880. classResult.studentScores[index][i] = 0;
  881. }
  882. }
  883. /*if (ans.Count == 0)
  884. {
  885. classResult.status[index] = 1;
  886. } */
  887. //}
  888. }
  889. index++;
  890. }
  891. }
  892. else
  893. {
  894. List<int> sta = new();
  895. foreach (var id in classResult.studentIds)
  896. {
  897. sta.Add(0);
  898. }
  899. classResult.status = sta;
  900. foreach (var ans in classResult.studentAnswers)
  901. {
  902. //该学生缺考,历史数据的判定
  903. if (ans.Count == 0)
  904. {
  905. for (int i = 0; i < classResult.studentScores[index].Count; i++)
  906. {
  907. if (classResult.studentScores[index][i] == -1)
  908. {
  909. classResult.studentScores[index][i] = 0;
  910. }
  911. }
  912. classResult.status[index] = 1;
  913. }
  914. index++;
  915. }
  916. }
  917. int sIndex = 0;
  918. foreach (List<double> sc in classResult.studentScores)
  919. {
  920. List<double> newSc = new List<double>();
  921. foreach (double ssc in sc)
  922. {
  923. if (ssc == -1)
  924. {
  925. newSc.Add(0);
  926. }
  927. else
  928. {
  929. newSc.Add(ssc);
  930. }
  931. }
  932. double nc = Math.Round(newSc.Sum(), 2);
  933. if (classResult.status[sIndex] == 0)
  934. {
  935. effectiveScore.Add(nc);
  936. };
  937. newSumScore.Add(nc);
  938. subScore += nc;
  939. classResult.sum[sIndex] = nc;
  940. sIndex++;
  941. }
  942. double rateScore = scount > 0 ? Math.Round(subScore * 1.0 / scount, 2) : 0;
  943. //有效分数
  944. foreach (double scs in effectiveScore)
  945. {
  946. sPowSum += Math.Pow(scs - rateScore, 2);
  947. }
  948. classResult.standard = Math.Round(scount > 0 ? Math.Pow(sPowSum / scount, 0.5) : 0, 2);
  949. classResult.average = scount > 0 ? Math.Round(subScore / scount, 2) : 0;
  950. classResult.progress = true;
  951. tasks.Add(client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"{classResult.code}")));
  952. }
  953. await Task.WhenAll(tasks);
  954. }
  955. public static async Task<Settlement> getMore(CosmosClient client, ExamInfo info)
  956. {
  957. //计算单次考试简易统计信息
  958. Settlement settlement = new();
  959. List<ExamResult> examResults = new();
  960. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<ExamResult>(
  961. queryText: $"select value(c) from c where c.examId = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamResult-{info.id}") }))
  962. {
  963. examResults.Add(item);
  964. }
  965. if (examResults.Count > 0)
  966. {
  967. //记录某次考试所有学生得分总分
  968. double score = 0;
  969. double allScore = 0;
  970. int stuCount = 0;
  971. //标准差
  972. double powSum = 0;
  973. List<string> losStu = new List<string>();
  974. //当前完成考试得人数
  975. int total = examResults[0].studentIds.Distinct().Count();
  976. //先与第一个值取并集
  977. losStu = losStu.Union(examResults[0].lostStus).ToList();
  978. foreach (ExamResult examResult in examResults)
  979. {
  980. //取交集
  981. losStu = losStu.Intersect(examResult.lostStus).ToList();
  982. }
  983. //处理缺考的学生
  984. List<string> stus = examResults[0].studentIds.Except(losStu).ToList();
  985. foreach (ExamResult examResult in examResults)
  986. {
  987. foreach (var id in stus)
  988. {
  989. int index = examResult.studentIds.IndexOf(id);
  990. score += examResult.studentScores[index].Sum();
  991. }
  992. }
  993. stuCount = total - losStu.Count;
  994. double NewsRateScore = stuCount > 0 ? Math.Round(score * 1.0 / stuCount, 2) : 0;
  995. foreach (PaperSimple simple in info.papers)
  996. {
  997. allScore += simple.point.Sum();
  998. }
  999. //计算全科标准差
  1000. foreach (string id in stus)
  1001. {
  1002. double sc = 0;
  1003. foreach (ExamResult result in examResults)
  1004. {
  1005. if (result.studentScores.Count > 0)
  1006. {
  1007. sc += result.studentScores[result.studentIds.IndexOf(id)].Sum();
  1008. }
  1009. }
  1010. powSum += Math.Pow(sc - NewsRateScore, 2);
  1011. }
  1012. info.standard = Math.Round(total - losStu.Count > 0 ? Math.Pow(powSum / (total - losStu.Count), 0.5) : 0, 2);
  1013. double NewsRate = allScore > 0 ? Math.Round(NewsRateScore / allScore * 100, 2) : 0;
  1014. double qrate = Math.Round(total > 0 ? losStu.Count * 1.0 / total * 100 : 0, 2);
  1015. settlement.rate = NewsRate;
  1016. settlement.score = NewsRateScore;
  1017. settlement.stus = losStu;
  1018. settlement.total = total;
  1019. settlement.qrate = qrate;
  1020. }
  1021. return settlement;
  1022. }
  1023. //处理全部学生选题计数
  1024. public static async Task examRecordCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no, ExamResult er, List<ExamClassResult> classResults, AzureCosmosFactory _azureCosmos)
  1025. {
  1026. try
  1027. {
  1028. List<double> scores = new List<double>();
  1029. foreach (List<double> sc in er.studentScores)
  1030. {
  1031. scores.Add(sc.Sum());
  1032. }
  1033. //确定高分组 最低分数
  1034. //var srowallorder = scores.EnumerateIndexed().OrderByDescending(g => g.Item2); //各生總分排序
  1035. //var srowallorder = scores.OrderByDescending(g => g);
  1036. double[] point = TEAMModelOS.SDK.Helper.Common.StringHelper.StringHelper.ListTodouble(er.paper.point);
  1037. double[,] result = TEAMModelOS.SDK.Helper.Common.StringHelper. StringHelper.ListToDouble(er.studentScores);
  1038. var cdm = new ClouDASMatrix(result, point);
  1039. scores.Sort((s1, s2) => { return s2.CompareTo(s1); });
  1040. int rhwCount = cdm.SH.Count();
  1041. double rhw = cdm.SH.LastOrDefault().Item2;
  1042. int rhlCount = cdm.SL.Count();
  1043. double rhl = cdm.SL.FirstOrDefault().Item2;
  1044. List<string> phs = new();
  1045. List<string> pls = new();
  1046. //分别获取高分组低分组人员
  1047. foreach (var ph in cdm.SH)
  1048. {
  1049. phs.Add(er.studentIds[ph.Item1]);
  1050. }
  1051. foreach (var pl in cdm.SL)
  1052. {
  1053. pls.Add(er.studentIds[pl.Item1]);
  1054. }
  1055. /* if (scores.Count > 3)
  1056. {
  1057. rhwCount = Convert.ToInt32(Math.Floor(scores.Count * 0.27));
  1058. rhw = rhwCount > 0 ? scores[rhwCount - 1] : 0;
  1059. rhlCount = Convert.ToInt32(Math.Ceiling(scores.Count * 0.73));
  1060. rhl = rhlCount > 0 ? scores[rhlCount] : 0;
  1061. }
  1062. else
  1063. {
  1064. rhwCount = Convert.ToInt32(Math.Floor(scores.Count * 0.27));
  1065. rhw = rhwCount > 0 ? scores[rhwCount] : 0;
  1066. rhlCount = Convert.ToInt32(Math.Ceiling(scores.Count * 0.73));
  1067. rhl = rhlCount > 0 ? scores[rhlCount - 1] : 0;
  1068. }*/
  1069. /*int rhwCount = Convert.ToInt32(Math.Floor(scores.Count * 0.27));
  1070. double rhw = rhwCount > 0 ? scores[rhwCount-1] : 0;
  1071. //var rhww = srowallorder.Take(Convert.ToInt32(Math.Floor(scores.Count * 0.27)));
  1072. //确定低分组 最高分数
  1073. //scores.Sort((s1, s2) => { return s1.CompareTo(s2); });
  1074. int rhlCount = Convert.ToInt32(Math.Ceiling(scores.Count * 0.73));
  1075. double rhl = rhlCount > 0 ? scores[rhlCount-1] : 0;*/
  1076. //var rhll = srowallorder.Skip(Convert.ToInt32(Math.Ceiling(scores.Count * 0.73)));
  1077. //存放高分组学生ID
  1078. List<string> phId = new();
  1079. List<string> plId = new();
  1080. List<List<List<string>>> opth = new();
  1081. List<List<List<string>>> optl = new();
  1082. List<double> akp = await knowledgeCount(info, subject, _dingDing, no, classResults, rhwCount, rhw, rhlCount, rhl, _azureCosmos);
  1083. List<double> afp = await fieldCount(info, subject, _dingDing, no, classResults, rhwCount, rhw, rhlCount, rhl, _azureCosmos);
  1084. int PHCount = 0;
  1085. int PLCount = 0;
  1086. foreach (ExamClassResult classResult in classResults)
  1087. {
  1088. if (classResult.subjectId.Equals(subject.id))
  1089. {
  1090. foreach (string id in classResult.studentIds)
  1091. {
  1092. int index = classResult.studentIds.IndexOf(id);
  1093. if (classResult.studentScores.Count > 0)
  1094. {
  1095. if (phs.Contains(id))
  1096. {
  1097. if (classResult.ans.Count > 0)
  1098. {
  1099. opth.Add(classResult.ans[index]);
  1100. PHCount++;
  1101. continue;
  1102. }
  1103. }
  1104. if (pls.Contains(id))
  1105. {
  1106. if (classResult.ans.Count > 0)
  1107. {
  1108. optl.Add(classResult.ans[index]);
  1109. PLCount++;
  1110. continue;
  1111. }
  1112. }
  1113. }
  1114. }
  1115. }
  1116. }
  1117. er.phc = getMore(info, no, opth);
  1118. er.plc = getMore(info, no, optl);
  1119. er.afp = afp;
  1120. er.akp = akp;
  1121. }
  1122. catch (Exception ex)
  1123. {
  1124. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测作答记录结算异常{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1125. }
  1126. }
  1127. public static async Task<List<RGroupList>> Activity(CoreAPIHttpService _coreAPIHttpService, ExamInfo info, List<string> classes, CosmosClient client, DingDing _dingDing, List<string> sub, List<ExamClassResult> results)
  1128. {
  1129. List<(string pId, List<string> gid)> ps = new List<(string pId, List<string> gid)>();
  1130. if (info.groupLists.Count > 0)
  1131. {
  1132. var group = info.groupLists;
  1133. foreach (var gp in group)
  1134. {
  1135. foreach (KeyValuePair<string, List<string>> pp in gp)
  1136. {
  1137. ps.Add((pp.Key, pp.Value));
  1138. }
  1139. }
  1140. }
  1141. (List<RMember> tchList, List<RGroupList> classLists) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, classes, info.school, ps);
  1142. /*
  1143. var addStudentsCls = tchList.FindAll(x => x.type == 2);
  1144. var addTmdidsCls = tchList.FindAll(x => x.type == 1);
  1145. List<StuActivity> stuActivities = new List<StuActivity>();
  1146. List<StuActivity> tmdActivities = new List<StuActivity>();
  1147. var papers = info.papers.GroupBy(c => c.subjectId).Select(x => new
  1148. {
  1149. subject = x.Key,
  1150. blob = x.ToList().Select(z => z.blob).ToList()
  1151. });
  1152. bool flag = info.papers.Exists(c => c.subjectId != null);
  1153. if (addTmdidsCls.IsNotEmpty())
  1154. {
  1155. addTmdidsCls.ForEach(x =>
  1156. {
  1157. HashSet<string> classIds = new HashSet<string>();
  1158. classLists.ForEach(z =>
  1159. {
  1160. z.members.ForEach(y =>
  1161. {
  1162. if (y.id.Equals(x.id) && y.type == 1)
  1163. {
  1164. classIds.Add(z.id);
  1165. }
  1166. });
  1167. });
  1168. bool iss = false;
  1169. //标记学生作答状态
  1170. int ts = 0;
  1171. if (results.Count > 0)
  1172. {
  1173. foreach (ExamClassResult exam in results)
  1174. {
  1175. int index = exam.studentIds.IndexOf(x.id);
  1176. if (index != -1)
  1177. {
  1178. if (exam.studentAnswers[index].Count > 0)
  1179. {
  1180. bool flag = exam.studentScores[index].Exists(x => x == -1);
  1181. if (!flag)
  1182. {
  1183. ts = 1;
  1184. iss = true;
  1185. break;
  1186. }
  1187. else
  1188. {
  1189. ts = 0;
  1190. }
  1191. }
  1192. else
  1193. {
  1194. ts = -1;
  1195. }
  1196. }
  1197. }
  1198. }
  1199. else
  1200. {
  1201. ts = -1;
  1202. }
  1203. tmdActivities.Add(new StuActivity
  1204. {
  1205. pk = "Activity",
  1206. id = info.id,
  1207. code = $"Activity-{x.id}",
  1208. type = "Exam",
  1209. name = info.name,
  1210. source = info.source,
  1211. startTime = info.startTime,
  1212. endTime = info.endTime,
  1213. scode = info.code,
  1214. scope = info.scope,
  1215. school = info.school,
  1216. creatorId = info.creatorId,
  1217. subjects = sub,
  1218. blob = null,
  1219. paper = flag ? papers.Select(c => new
  1220. {
  1221. c.subject,
  1222. blob = c.blob[new Random().Next(c.blob.Count)]
  1223. }) : "",
  1224. owner = info.owner,
  1225. createTime = info.createTime,
  1226. taskStatus = ts,
  1227. qamode = info.qamode,
  1228. ext = new Dictionary<string, JsonElement>() { { "type", info.examType.ToJsonString().ToObject<JsonElement>() },
  1229. { "subjects", info.subjects.ToJsonString().ToObject<JsonElement>() } },
  1230. sStatus = iss ? 1 : 0,
  1231. classIds = classIds.ToList()
  1232. }); ;
  1233. });
  1234. }
  1235. if (addStudentsCls.IsNotEmpty())
  1236. {
  1237. addStudentsCls.ForEach(x =>
  1238. {
  1239. HashSet<string> classIds = new HashSet<string>();
  1240. classLists.ForEach(z =>
  1241. {
  1242. z.members.ForEach(y =>
  1243. {
  1244. if (y.id.Equals(x.id) && y.code.Equals(info.school) && y.type == 2)
  1245. {
  1246. classIds.Add(z.id);
  1247. }
  1248. });
  1249. });
  1250. bool iss = false;
  1251. //标记学生作答状态
  1252. int ts = 0;
  1253. if (results.Count > 0)
  1254. {
  1255. foreach (ExamClassResult exam in results)
  1256. {
  1257. int index = exam.studentIds.IndexOf(x.id);
  1258. if (index != -1)
  1259. {
  1260. if (exam.studentAnswers[index].Count > 0)
  1261. {
  1262. bool flag = exam.studentScores[index].Exists(x => x == -1);
  1263. if (!flag)
  1264. {
  1265. ts = 1;
  1266. iss = true;
  1267. break;
  1268. }
  1269. else
  1270. {
  1271. ts = 0;
  1272. }
  1273. }
  1274. else
  1275. {
  1276. ts = -1;
  1277. }
  1278. }
  1279. }
  1280. }
  1281. else
  1282. {
  1283. ts = -1;
  1284. }
  1285. stuActivities.Add(new StuActivity
  1286. {
  1287. pk = "Activity",
  1288. id = info.id,
  1289. code = $"Activity-{x.code.Replace("Base-", "")}-{x.id}",
  1290. type = "Exam",
  1291. name = info.name,
  1292. source = info.source,
  1293. startTime = info.startTime,
  1294. endTime = info.endTime,
  1295. scode = info.code,
  1296. scope = info.scope,
  1297. school = info.school,
  1298. creatorId = info.creatorId,
  1299. subjects = sub,
  1300. blob = null,
  1301. paper = flag ? papers.Select(c => new
  1302. {
  1303. c.subject,
  1304. blob = c.blob[new Random().Next(c.blob.Count)]
  1305. }) : "",
  1306. owner = info.owner,
  1307. classIds = classIds.ToList(),
  1308. createTime = info.createTime,
  1309. qamode = info.qamode,
  1310. ext = new Dictionary<string, JsonElement>() { { "type", info.examType.ToJsonString().ToObject<JsonElement>() },
  1311. { "subjects", info.subjects.ToJsonString().ToObject<JsonElement>() } },
  1312. taskStatus = ts,
  1313. sStatus = iss ? 1 : 0,
  1314. });
  1315. });
  1316. }
  1317. await IESActivityService.SaveStuActivity(client, _dingDing, stuActivities, tmdActivities, null);
  1318. */
  1319. return classLists;
  1320. }
  1321. public static async Task<List<double>> knowledgeCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no, List<ExamClassResult> classResults,
  1322. double rhwCount, double rhw, double rhlCount, double rhl, AzureCosmosFactory _azureCosmos)
  1323. {
  1324. List<double> akp = new();
  1325. try
  1326. {
  1327. int phcount = 0;
  1328. int plcount = 0;
  1329. //存放并去重知识点
  1330. HashSet<string> kname = new HashSet<string>();
  1331. if (info.papers[no].knowledge.Count > 0)
  1332. {
  1333. info.papers[no].knowledge.ForEach(kno =>
  1334. {
  1335. kno.ForEach(k =>
  1336. {
  1337. kname.Add(k);
  1338. });
  1339. });
  1340. List<string> knowledgeName = new List<string>();
  1341. foreach (string cla in kname)
  1342. {
  1343. knowledgeName.Add(cla);
  1344. }
  1345. for (int k = 0; k < knowledgeName.Count; k++)
  1346. {
  1347. if (null == knowledgeName[k])
  1348. {
  1349. knowledgeName.Remove(knowledgeName[k]);
  1350. }
  1351. }
  1352. foreach (ExamClassResult classResult in classResults)
  1353. {
  1354. if (classResult.subjectId.Equals(subject.id))
  1355. {
  1356. //List<int> phc = new List<int>();
  1357. List<int> ph = new List<int>();
  1358. List<int> pl = new List<int>();
  1359. List<int> pc = new List<int>();
  1360. List<double> persent = new List<double>();
  1361. int lostStu = classResult.status.Where(c => c == 1).ToList().Count;
  1362. for (int i = 0; i < knowledgeName.Count; i++)
  1363. {
  1364. //初始化单个知识点得分
  1365. double score = 0;
  1366. int n = 0;
  1367. int phCount = 0;
  1368. int plCount = 0;
  1369. int pCount = 0;
  1370. double classScore = 0;
  1371. foreach (List<string> str in info.papers[no].knowledge)
  1372. {
  1373. if (str.Contains(knowledgeName[i]))
  1374. {
  1375. var itemPersent = str.Count > 0 ? 1 / Convert.ToDouble(str.Count) : 0;
  1376. classScore += info.papers[no].point.Count > 0 ? (info.papers[no].point[n] * itemPersent) : 0;
  1377. foreach (string id in classResult.studentIds)
  1378. {
  1379. int index = classResult.studentIds.IndexOf(id);
  1380. if (classResult.studentScores.Count > 0)
  1381. {
  1382. if (classResult.studentScores[index].Count > 0)
  1383. {
  1384. double realScore = classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n] * itemPersent;
  1385. score += realScore;
  1386. //score += classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n] * itemPersent;
  1387. if (classResult.studentScores[index].Sum() >= rhw && phcount < rhwCount)
  1388. {
  1389. if (classResult.studentScores[index][n] <= 0)
  1390. {
  1391. phCount++;
  1392. }
  1393. phcount++;
  1394. continue;
  1395. }
  1396. if (classResult.studentScores[index].Sum() <= rhl && plcount < (info.stuCount - rhlCount))
  1397. {
  1398. if (classResult.studentScores[index][n] <= 0)
  1399. {
  1400. plCount++;
  1401. }
  1402. plcount++;
  1403. continue;
  1404. }
  1405. if (classResult.studentScores[index][n] <= 0)
  1406. {
  1407. pCount++;
  1408. }
  1409. }
  1410. }
  1411. }
  1412. }
  1413. n++;
  1414. }
  1415. pc.Add(pCount);
  1416. ph.Add(phCount);
  1417. pl.Add(plCount);
  1418. double per = classResult.studentIds.Count - lostStu > 0 ? Math.Round(score / (classResult.studentIds.Count - lostStu), 2) : 0;
  1419. persent.Add(classScore > 0 ? Math.Round(per * 1.0 / classScore, 2) : 0);
  1420. }
  1421. classResult.phc = ph;
  1422. classResult.plc = pl;
  1423. classResult.pc = pc;
  1424. classResult.krate = persent;
  1425. }
  1426. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"{classResult.code}"));
  1427. }
  1428. foreach (string k in knowledgeName)
  1429. {
  1430. double score = 0;
  1431. double allScore = 0;
  1432. int count = 0;
  1433. int m = 0;
  1434. foreach (List<string> str in info.papers[no].knowledge)
  1435. {
  1436. if (str.Contains(k))
  1437. {
  1438. var itemPersent = str.Count > 0 ? 1 / Convert.ToDouble(str.Count) : 0;
  1439. allScore += info.papers[no].point.Count > 0 ? info.papers[no].point[m] * itemPersent : 0;
  1440. }
  1441. m++;
  1442. }
  1443. foreach (ExamClassResult result in classResults)
  1444. {
  1445. if (result.subjectId.Equals(subject.id))
  1446. {
  1447. int n = 0;
  1448. foreach (List<string> str in info.papers[no].knowledge)
  1449. {
  1450. if (str.Contains(k))
  1451. {
  1452. var itemPersent = str.Count > 0 ? 1 / Convert.ToDouble(str.Count) : 0;
  1453. if (result.studentScores.Count > 0)
  1454. {
  1455. foreach (List<double> sc in result.studentScores)
  1456. {
  1457. double tsc = sc[n] == -1 ? 0 : sc[n];
  1458. score += (tsc * itemPersent);
  1459. }
  1460. }
  1461. }
  1462. n++;
  1463. }
  1464. count += result.studentIds.Count;
  1465. }
  1466. }
  1467. double per = count - info.lostStu.Count > 0 ? Math.Round(score / (count - info.lostStu.Count), 2) : 0;
  1468. akp.Add(allScore > 0 ? Math.Round(per / allScore, 2) : 0);
  1469. }
  1470. }
  1471. return akp;
  1472. }
  1473. catch (Exception ex)
  1474. {
  1475. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测知识点结算异常{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1476. return null;
  1477. }
  1478. }
  1479. public static async Task<List<double>> fieldCount(ExamInfo info, ExamSubject subject, DingDing _dingDing, int no, List<ExamClassResult> classResults,
  1480. double rhwCount, double rhw, double rhlCount, double rhl, AzureCosmosFactory _azureCosmos)
  1481. {
  1482. List<double> afp = new();
  1483. try
  1484. {
  1485. int phcount = 0;
  1486. int plcount = 0;
  1487. //存放并去重知识点
  1488. List<int> knowledgeName = new List<int>() { 1, 2, 3, 4, 5, 6 };
  1489. /* knowledgeName.Add(1);
  1490. knowledgeName.Add(2);
  1491. knowledgeName.Add(3);
  1492. knowledgeName.Add(4);
  1493. knowledgeName.Add(5);
  1494. knowledgeName.Add(6);*/
  1495. foreach (ExamClassResult classResult in classResults)
  1496. {
  1497. if (classResult.subjectId.Equals(subject.id))
  1498. {
  1499. //List<int> phc = new List<int>();
  1500. List<int> ph = new List<int>();
  1501. List<int> pl = new List<int>();
  1502. List<int> pc = new List<int>();
  1503. List<double> persent = new List<double>();
  1504. int lostStu = classResult.status.Where(c => c == 1).ToList().Count;
  1505. for (int i = 0; i < knowledgeName.Count; i++)
  1506. {
  1507. //初始化单个知识点得分
  1508. double score = 0;
  1509. int n = 0;
  1510. int phCount = 0;
  1511. int plCount = 0;
  1512. int pCount = 0;
  1513. double classScore = 0;
  1514. if (info.papers[no].field.Count > 0)
  1515. {
  1516. foreach (int str in info.papers[no].field)
  1517. {
  1518. if (str == knowledgeName[i])
  1519. {
  1520. var itemPersent = 1;
  1521. classScore += info.papers[no].point.Count > 0 ? info.papers[no].point[n] * itemPersent : 0;
  1522. foreach (string id in classResult.studentIds)
  1523. {
  1524. int index = classResult.studentIds.IndexOf(id);
  1525. if (classResult.studentScores.Count > 0)
  1526. {
  1527. if (classResult.studentScores[index].Count > 0)
  1528. {
  1529. score += classResult.studentScores[index][n] == -1 ? 0 : classResult.studentScores[index][n];
  1530. if (classResult.studentScores[index].Sum() >= rhw && phcount < rhwCount)
  1531. {
  1532. if (classResult.studentScores[index][n] <= 0)
  1533. {
  1534. phCount++;
  1535. }
  1536. phcount++;
  1537. continue;
  1538. }
  1539. if (classResult.studentScores[index].Sum() <= rhl && plcount < (info.stuCount - rhlCount))
  1540. {
  1541. if (classResult.studentScores[index][n] <= 0)
  1542. {
  1543. plCount++;
  1544. }
  1545. plcount++;
  1546. continue;
  1547. }
  1548. if (classResult.studentScores[index][n] <= 0)
  1549. {
  1550. pCount++;
  1551. }
  1552. }
  1553. }
  1554. }
  1555. }
  1556. n++;
  1557. }
  1558. pc.Add(pCount);
  1559. ph.Add(phCount);
  1560. pl.Add(plCount);
  1561. double per = classResult.studentIds.Count - lostStu > 0 ? Math.Round(score / (classResult.studentIds.Count - lostStu), 2) : 0;
  1562. persent.Add(classScore > 0 ? Math.Round(per / classScore, 2) : 0);
  1563. }
  1564. }
  1565. classResult.fphc = ph;
  1566. classResult.fplc = pl;
  1567. classResult.fpc = pc;
  1568. classResult.frate = persent;
  1569. }
  1570. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"{classResult.code}"));
  1571. }
  1572. for (int i = 0; i < knowledgeName.Count; i++)
  1573. {
  1574. double score = 0;
  1575. double allScore = 0;
  1576. int count = 0;
  1577. int m = 0;
  1578. foreach (int str in info.papers[no].field)
  1579. {
  1580. if (str == knowledgeName[i])
  1581. {
  1582. var itemPersent = 1;
  1583. allScore += info.papers[no].point.Count > 0 ? info.papers[no].point[m] * itemPersent : 0;
  1584. }
  1585. m++;
  1586. }
  1587. foreach (ExamClassResult result in classResults)
  1588. {
  1589. if (result.subjectId.Equals(subject.id))
  1590. {
  1591. int n = 0;
  1592. foreach (int str in info.papers[no].field)
  1593. {
  1594. var itemPersent = 1;
  1595. if (str == knowledgeName[i])
  1596. {
  1597. if (result.studentScores.Count > 0)
  1598. {
  1599. foreach (List<double> sc in result.studentScores)
  1600. {
  1601. double tsc = sc[n] == -1 ? 0 : sc[n];
  1602. score += tsc * itemPersent;
  1603. }
  1604. }
  1605. }
  1606. n++;
  1607. }
  1608. count += result.studentIds.Count;
  1609. }
  1610. }
  1611. double per = count - info.lostStu.Count > 0 ? Math.Round(score / (count - info.lostStu.Count), 2) : 0;
  1612. afp.Add(allScore > 0 ? Math.Round(per / allScore, 2) : 0);
  1613. }
  1614. return afp;
  1615. }
  1616. catch (Exception ex)
  1617. {
  1618. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测认知层次结算异常{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1619. return null;
  1620. }
  1621. }
  1622. //处理选题计数
  1623. public static List<Dictionary<string, int>> getMore(ExamInfo info, int no, List<List<List<string>>> list)
  1624. {
  1625. List<Dictionary<string, int>> recorde = new List<Dictionary<string, int>>();
  1626. try
  1627. {
  1628. for (int i = 0; i < info.papers[no].answers.Count; i++)
  1629. {
  1630. if (info.papers[no].answers[i].Count <= 0)
  1631. {
  1632. recorde.Add(new Dictionary<string, int>());
  1633. continue;
  1634. }
  1635. Dictionary<string, int> optCount = new Dictionary<string, int>();
  1636. foreach (List<List<string>> stu in list)
  1637. {
  1638. if (stu.Count == info.papers[no].answers.Count)
  1639. {
  1640. var item = stu[i];
  1641. foreach (string opt in item)
  1642. {
  1643. if (optCount.ContainsKey(opt))
  1644. {
  1645. optCount[opt] = optCount[opt] + 1;
  1646. }
  1647. else
  1648. {
  1649. optCount[opt] = 1;
  1650. }
  1651. }
  1652. }
  1653. }
  1654. recorde.Add(optCount);
  1655. }
  1656. return recorde;
  1657. }
  1658. catch (Exception)
  1659. {
  1660. return recorde;
  1661. }
  1662. }
  1663. public static async Task createClassResultAsync(ExamInfo info, List<ExamClassResult> examClassResults, ExamSubject subject, int no, AzureCosmosFactory _azureCosmos, DingDing _dingDing, AzureStorageFactory _azureStorage, IHttpClientFactory _httpClient, IConfiguration _configuration)
  1664. {
  1665. //保证试卷信息与科目信息同步
  1666. ExamResult result = new ExamResult();
  1667. //人数总和
  1668. int Count = 0;
  1669. int m = 0;
  1670. double score = 0;
  1671. //标准差
  1672. //double powSum = 0;
  1673. double allScore = info.papers[no].point.Sum();
  1674. List<ClassRange> classRanges = new List<ClassRange>();
  1675. List<string> lostStu = new List<string>();
  1676. List<double> csRate = new List<double>();
  1677. List<List<List<string>>> opt = new List<List<List<string>>>();
  1678. //List<Task<ItemResponse<ExamClassResult>>> tasks = new();
  1679. foreach (ExamClassResult classResult in examClassResults)
  1680. {
  1681. double classSrate = 0;
  1682. if (classResult.subjectId.Equals(subject.id))
  1683. {
  1684. foreach (List<List<string>> op in classResult.ans)
  1685. {
  1686. opt.Add(op);
  1687. }
  1688. //记录缺考学生索引位置
  1689. int index_stu = 0;
  1690. foreach (var ans in classResult.studentAnswers)
  1691. {
  1692. if (ans.Count == 0)
  1693. {
  1694. if (!lostStu.Contains(classResult.studentIds[index_stu]))
  1695. {
  1696. lostStu.Add(classResult.studentIds[index_stu]);
  1697. }
  1698. }
  1699. else
  1700. {
  1701. if (classResult.status[index_stu] == 1)
  1702. {
  1703. if (!lostStu.Contains(classResult.studentIds[index_stu]))
  1704. {
  1705. lostStu.Add(classResult.studentIds[index_stu]);
  1706. }
  1707. }
  1708. }
  1709. index_stu++;
  1710. }
  1711. int index = 0;
  1712. foreach (List<double> scores in classResult.studentScores)
  1713. {
  1714. List<double> newScores = new List<double>();
  1715. //int count = 0;
  1716. if (scores.Count > 0)
  1717. {
  1718. foreach (double sc in scores)
  1719. {
  1720. newScores.Add(sc > -1 ? sc : 0);
  1721. }
  1722. }
  1723. else
  1724. {
  1725. newScores.Add(0);
  1726. }
  1727. classSrate += newScores.Sum();
  1728. score += newScores.Sum();
  1729. result.studentScores.Add(newScores);
  1730. index++;
  1731. }
  1732. //处理班级信息
  1733. ClassRange range = new ClassRange();
  1734. range.id = classResult.info.id;
  1735. range.name = classResult.info.name;
  1736. range.gradeId = classResult.gradeId;
  1737. List<int> ran = new List<int>();
  1738. int stuCount = classResult.studentIds.Count;
  1739. //todo 与实际的缺考人数比较
  1740. int lostStus = classResult.status.Where(c => c == 1).ToList().Count;
  1741. Count += stuCount;
  1742. if (m == 0)
  1743. {
  1744. ran.Add(0);
  1745. ran.Add(stuCount - 1);
  1746. }
  1747. else
  1748. {
  1749. ran.Add(Count - stuCount);
  1750. ran.Add(Count - 1);
  1751. }
  1752. m++;
  1753. range.range = ran;
  1754. classRanges.Add(range);
  1755. //处理学生ID
  1756. foreach (string id in classResult.studentIds)
  1757. {
  1758. result.studentIds.Add(id);
  1759. }
  1760. if (allScore > 0)
  1761. {
  1762. csRate.Add(classResult.studentIds.Count - lostStus > 0 ? Math.Round(classSrate * 1.0 / (classResult.studentIds.Count - lostStus), 2) : 0 / allScore);
  1763. }
  1764. else
  1765. {
  1766. csRate.Add(0);
  1767. }
  1768. //powSum += Math.Pow(classSrate - result.average, 2);
  1769. //处理选项计数内容
  1770. }
  1771. //tasks.Add(_azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new PartitionKey($"{classResult.code}")));
  1772. }
  1773. //await tasks.TaskPage(10);
  1774. /*foreach (string id in result.lostStus) {
  1775. if (!examClassResults[0].studentIds.Contains(id)) {
  1776. int index = result.lostStus.IndexOf(id);
  1777. result.lostStus.RemoveAt(index);
  1778. }
  1779. }*/
  1780. //处理人员变更时被移除的人员
  1781. result.lostStus = lostStu;
  1782. List<string> stuIds = examClassResults.SelectMany(x => x.studentIds).ToList();
  1783. if (result.lostStus.Count > 0)
  1784. {
  1785. for (int i = 0; i < result.lostStus.Count; i++)
  1786. {
  1787. if (!stuIds.Contains(result.lostStus[i]))
  1788. {
  1789. result.lostStus.RemoveAt(i);
  1790. }
  1791. }
  1792. }
  1793. result.record = getMore(info, no, opt);
  1794. result.average = result.studentIds.Count - result.lostStus.Count > 0 ? Math.Round(score * 1.0 / (result.studentIds.Count - result.lostStus.Count), 2) : 0;
  1795. double powSum = 0;
  1796. //int sco = 0;
  1797. result.studentIds.ForEach(x =>
  1798. {
  1799. double sc = result.studentScores[result.studentIds.IndexOf(x)].Sum();
  1800. if (!result.lostStus.Contains(x))
  1801. {
  1802. powSum += Math.Pow(sc - result.average, 2);
  1803. }
  1804. });
  1805. result.standard = Math.Round((result.studentIds.Count - result.lostStus.Count) > 0 ? Math.Pow(powSum / (result.studentIds.Count - result.lostStus.Count), 0.5) : 0, 2);
  1806. result.csRate = csRate;
  1807. result.sRate = allScore > 0 ? Math.Round(result.average / allScore * 100, 2) : 0;
  1808. result.classes = classRanges;
  1809. result.code = "ExamResult-" + info.id;
  1810. result.school = info.school;
  1811. result.id = subject.id;
  1812. result.examId = info.id;
  1813. result.subjectId = subject.id;
  1814. result.year = info.year;
  1815. result.paper = info.papers[no];
  1816. //result.point = info.papers[j].point;
  1817. result.scope = info.scope;
  1818. result.name = info.name;
  1819. result.time = info.startTime;
  1820. //if (info.qamode != 2) {
  1821. await examRecordCount(info, subject, _dingDing, no, result, examClassResults, _azureCosmos);
  1822. //}
  1823. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").UpsertItemAsync(result, new PartitionKey($"ExamResult-{info.id}"));
  1824. List<ErrorItems> errorItems = new();
  1825. string code = string.Empty;
  1826. string pk = string.Empty;
  1827. string table = "School";
  1828. if (info.scope.Equals("school"))
  1829. {
  1830. code = $"ErrorItems-{info.school}";
  1831. pk = $"Item-{info.school}";
  1832. }
  1833. else
  1834. {
  1835. code = "ErrorItems";
  1836. pk = $"Item-{info.creatorId}";
  1837. table = "Teacher";
  1838. }
  1839. if (result.studentIds.Any()) {
  1840. 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}'"))})";
  1841. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Student").GetItemQueryIteratorSql<ErrorItems>(queryText: sqlqueryText, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
  1842. {
  1843. errorItems.Add(item);
  1844. }
  1845. try
  1846. {
  1847. /* bool isError = examClassResults.SelectMany(c => c.status).ToList().Exists(z => z == 1);
  1848. if () {
  1849. }*/
  1850. if (errorItems.Count == 0 && info.qamode != 2)
  1851. {
  1852. // 新增逻辑 收集错题内容
  1853. BlobDownloadResult index_json;
  1854. if (info.scope.Equals("school"))
  1855. {
  1856. index_json = await _azureStorage.GetBlobContainerClient($"{info.school}").GetBlobClient($"{info.papers[no].blob}/index.json").DownloadContentAsync();
  1857. }
  1858. else
  1859. {
  1860. index_json = await _azureStorage.GetBlobContainerClient($"{info.creatorId}").GetBlobClient($"{info.papers[no].blob}/index.json").DownloadContentAsync();
  1861. }
  1862. //BlobDownloadResult index_json = await _azureStorage.GetBlobContainerClient($"{info.school}").GetBlobClient($"{info.papers[no].blob}/index.json").DownloadContentAsync();
  1863. JsonElement RecordingJson = JsonDocument.Parse(new MemoryStream(Encoding.UTF8.GetBytes(index_json.Content.ToString()))).RootElement;
  1864. RecordingJson.TryGetProperty("slides", out JsonElement slides);
  1865. int qamode = info.qamode;
  1866. if (RecordingJson.TryGetProperty("qamode", out JsonElement element))
  1867. {
  1868. qamode = element.GetInt32();
  1869. }
  1870. var sdes = slides.ToObject<List<Slides>>();
  1871. List<string> attachments = new List<string>();
  1872. if (qamode == 1)
  1873. {
  1874. attachments = RecordingJson.GetProperty("attachments").ToObject<List<string>>();
  1875. if (attachments.Count == 0)
  1876. {
  1877. return;
  1878. }
  1879. }
  1880. List<string> urls = new();
  1881. foreach (var ne in sdes)
  1882. {
  1883. if (!ne.type.Equals("compose"))
  1884. {
  1885. urls.Add(ne.url);
  1886. }
  1887. }
  1888. // 获取整体的题目ID集合
  1889. List<string> ids = new();
  1890. List<(string id, string pid, int level, string type, List<string> knows)> itemInfos = new();
  1891. foreach (string url in urls)
  1892. {
  1893. string id = url.Replace(".json", "");
  1894. BlobDownloadResult index_item_json;
  1895. if (info.scope.Equals("school"))
  1896. {
  1897. index_item_json = await _azureStorage.GetBlobContainerClient($"{info.school}").GetBlobClient($"{info.papers[no].blob}/{url}").DownloadContentAsync();
  1898. }
  1899. else
  1900. {
  1901. index_item_json = await _azureStorage.GetBlobContainerClient($"{info.creatorId}").GetBlobClient($"{info.papers[no].blob}/{url}").DownloadContentAsync();
  1902. }
  1903. JsonElement itemJson = JsonDocument.Parse(new MemoryStream(Encoding.UTF8.GetBytes(index_item_json.Content.ToString()))).RootElement;
  1904. itemJson.TryGetProperty("exercise", out JsonElement exercise);
  1905. //itemJson.TryGetProperty("pid", out JsonElement pid);
  1906. var item_json = exercise.ToObject<Exercise>();
  1907. //JObject keys = JObject.Parse(index_item_json.Content.ToString());
  1908. string type = item_json.type;
  1909. int level = item_json.level;
  1910. var knowledge = item_json.knowledges;
  1911. //string pid = keys.Value<string>("pid");
  1912. if (itemJson.TryGetProperty("pid", out JsonElement pid))
  1913. {
  1914. itemInfos.Add((id, pid.ToString(), level, type, knowledge));
  1915. }
  1916. else
  1917. {
  1918. itemInfos.Add((id, "", level, type, knowledge));
  1919. }
  1920. }
  1921. /* double[] point = StringHelper.ListTodouble(result.paper.point);
  1922. double[,] res = StringHelper.ListToDouble(result.studentScores);
  1923. var cdm = new ClouDASMatrix(res, point);*/
  1924. //需要努力的题目
  1925. //var ss = cdm.StriveTopic;
  1926. int n = 0;
  1927. List<Task<ItemResponse<ErrorItems>>> task_error = new();
  1928. List<ErrorItems> errors = new();
  1929. foreach (var sIds in result.studentIds)
  1930. {
  1931. ErrorItems error = new()
  1932. {
  1933. ttl = -1,
  1934. code = code,
  1935. id = Guid.NewGuid().ToString(),
  1936. stuId = sIds,
  1937. school = info.school,
  1938. activityId = info.id,
  1939. subjectId = result.subjectId,
  1940. time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
  1941. };
  1942. int index_stu = result.studentIds.IndexOf(sIds);
  1943. //顺序学生错题的索引
  1944. var itemScore = result.studentScores[index_stu];
  1945. List<int> index = new();
  1946. int index_item = 0;
  1947. foreach (var sc in itemScore)
  1948. {
  1949. if (sc == 0)
  1950. {
  1951. index.Add(index_item + 1);
  1952. }
  1953. index_item++;
  1954. }
  1955. if (index.Count == 0)
  1956. {
  1957. continue;
  1958. }
  1959. //int[] item_index = ss[n];
  1960. foreach (var item in index)
  1961. {
  1962. Items items = new()
  1963. {
  1964. id = urls[item - 1].Replace(".json", ""),
  1965. blob = info.papers[no].blob
  1966. };
  1967. items.level = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().level;
  1968. items.type = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().type;
  1969. items.pId = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().pid;
  1970. items.knowledge = itemInfos.Where(c => c.id.Equals(items.id)).FirstOrDefault().knows;
  1971. items.qamode = qamode;
  1972. error.its.Add(items);
  1973. }
  1974. errors.Add(error);
  1975. n++;
  1976. task_error.Add(_azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").CreateItemAsync(error, new PartitionKey($"{error.code}")));
  1977. }
  1978. //string connect = _configuration.GetValue<string>("HaBookAuth:Crtmabank") + "https://malearnfunction.chinacloudsites.cn/api/crtmabank";
  1979. string location = $"{Environment.GetEnvironmentVariable("Option:Location")}";
  1980. string urlAction = string.Empty;
  1981. string accessKey = string.Empty;
  1982. if (location.Contains("China"))
  1983. {
  1984. if (location.Equals("China")) //大陸正式站
  1985. {
  1986. urlAction = "https://malearn.teammodel.cn";
  1987. accessKey = "2BcXFR_hvzG1pZjqIkaM7Dx74Hcu6m0PwwOacFpDpq44AzFuHJBRXA==";
  1988. }
  1989. else if (location.Equals("China-Dep") || location.Equals("China-Test")) //大陸測試站
  1990. {
  1991. urlAction = "https://malearn-rc.teammodel.cn";
  1992. accessKey = "lghWhJduNiAlo-e8isqEoROjdR7DAC-50XNtanIwHKYlAzFu1aog_A==";
  1993. }
  1994. }
  1995. else if (location.Contains("Global"))
  1996. {
  1997. if (location.Equals("Global")) //國際正式站
  1998. {
  1999. urlAction = "https://malearn.teammodel.net";
  2000. accessKey = "I-2lTcdggJkZWSBwOXQIm4oHx-huwX3d0wLe-9pgojThAzFuq_KNFg==";
  2001. }
  2002. else if (location.Equals("Global-Test")) //國際測試站
  2003. {
  2004. urlAction = "https://malearn-rc.teammodel.net";
  2005. accessKey = "_l4Cb_tHIRBw_iv3ZuwVqjkMwjg4_HtDaxhAmZ8OwJraAzFu_DAY8A==";
  2006. }
  2007. }
  2008. string connect = $"{urlAction}/api/crtmabank";
  2009. var htc = _httpClient.CreateClient();
  2010. if (htc.DefaultRequestHeaders.Contains("x-functions-key"))
  2011. {
  2012. htc.DefaultRequestHeaders.Remove("x-functions-key");
  2013. }
  2014. htc.DefaultRequestHeaders.Add("x-functions-key", accessKey);
  2015. ///智慧題庫school欄位修正
  2016. foreach (ErrorItems error in errors)
  2017. {
  2018. error.school = (info.scope.Equals("school")) ? info.school : string.Empty;
  2019. }
  2020. string paramJson = JsonConvert.SerializeObject(errors);
  2021. var content = new StringContent(paramJson, Encoding.UTF8, "application/json");
  2022. var response = await htc.PostAsync(connect, content);
  2023. if ((int)response.StatusCode == 200)
  2024. {
  2025. await task_error.TaskPage(10);
  2026. }
  2027. }
  2028. }
  2029. catch (Exception e)
  2030. {
  2031. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测错题异常{e.Message}\n{e.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  2032. }
  2033. }
  2034. }
  2035. public class Settlement
  2036. {
  2037. public double rate { get; set; }
  2038. public double score { get; set; }
  2039. public List<string> stus { get; set; } = new List<string>();
  2040. public int total { get; set; }
  2041. public double qrate { get; set; }
  2042. }
  2043. #region ===學習記錄用類別===
  2044. private class PaperIndex
  2045. {
  2046. public PaperIndex()
  2047. {
  2048. slides = new List<Slide>();
  2049. }
  2050. public List<Slide> slides { get; set; }
  2051. }
  2052. private class Slide
  2053. {
  2054. /// <summary>
  2055. /// blob 路徑
  2056. /// </summary>
  2057. public string url { get; set; }
  2058. /// <summary>
  2059. /// 題型
  2060. /// </summary>
  2061. public string type { get; set; }
  2062. /// <summary>
  2063. /// scoring
  2064. /// </summary>
  2065. public Scoring scoring { get; set; }
  2066. }
  2067. private class Exercise
  2068. {
  2069. /// <summary>
  2070. /// 题目类型
  2071. /// </summary>
  2072. public string type { get; set; }
  2073. /// <summary>
  2074. /// 难度
  2075. /// </summary>
  2076. public int level { get; set; }
  2077. /// <summary>
  2078. /// 知识点
  2079. /// </summary>
  2080. public List<string> knowledges { get; set; }
  2081. }
  2082. private class Scoring
  2083. {
  2084. /// <summary>
  2085. /// knowledge
  2086. /// </summary>
  2087. public List<string> knowledge { get; set; }
  2088. /// <summary>
  2089. /// 答案
  2090. /// </summary>
  2091. public List<string> ans { get; set; }
  2092. }
  2093. private class StudentAnswers
  2094. {
  2095. /// <summary>
  2096. /// 學生作答 blob 路徑
  2097. /// </summary>
  2098. public List<List<string>> studentAnswers { get; set; }
  2099. /// <summary>
  2100. /// 學生ID
  2101. /// </summary>
  2102. public List<string> studentIds { get; set; } = new();
  2103. }
  2104. private class QuestionData
  2105. {
  2106. public QuestionData()
  2107. {
  2108. item = new List<QuestionItem>();
  2109. }
  2110. public QuestionExercise exercise { get; set; }
  2111. public List<QuestionItem> item { get; set; }
  2112. }
  2113. private class QuestionItem
  2114. {
  2115. public QuestionItem()
  2116. {
  2117. option = new List<OptionItem>();
  2118. }
  2119. public string question { get; set; }
  2120. public List<OptionItem> option { get; set; }
  2121. }
  2122. private class OptionItem
  2123. {
  2124. public string code { get; set; }
  2125. public string value { get; set; }
  2126. }
  2127. private class QuestionExercise
  2128. {
  2129. public string type { get; set; }
  2130. public List<string> knowledge { get; set; }
  2131. public List<string> answer { get; set; }
  2132. }
  2133. #endregion
  2134. }
  2135. }