ArtService.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. using Microsoft.Azure.Cosmos;
  2. using Azure.Messaging.ServiceBus;
  3. using Microsoft.Extensions.Configuration;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Text.Json;
  10. using System.Threading.Tasks;
  11. using TEAMModelOS.SDK.DI;
  12. using TEAMModelOS.SDK.Extension;
  13. using TEAMModelOS.SDK.Models.Cosmos.Common;
  14. using static TEAMModelOS.SDK.Models.ClassAnalysis;
  15. namespace TEAMModelOS.SDK.Models.Service
  16. {
  17. public static class ArtService
  18. {
  19. public static List<ArtQuota> GetParentByChildId(List<ArtQuota> quotas, string childId) {
  20. List<ArtQuota> list_quotas = new List<ArtQuota>();
  21. list_quotas = TreeToList(quotas, list_quotas, null);
  22. List<ArtQuota> parents = new List<ArtQuota>();
  23. parents = GetParents(list_quotas, parents, $"{childId}");
  24. if (parents.IsNotEmpty()) {
  25. int len = parents.Count;
  26. parents.ForEach(x => {
  27. x.level= len-x.level+1;
  28. });
  29. }
  30. return parents;
  31. }
  32. private static List<ArtQuota> GetParents(List<ArtQuota> list, List<ArtQuota> parents, string cid, int level = 1)
  33. {
  34. var child = list.Find(x => x.id.Equals(cid));
  35. if (child != null)
  36. {
  37. child.level = level;
  38. parents.Add(child);
  39. if (!child.pid.Equals(child.id))
  40. {
  41. level++;
  42. return GetParents(list, parents, child.pid, level);
  43. }
  44. else
  45. {
  46. return parents;
  47. }
  48. }
  49. else { return parents; }
  50. }
  51. private static List<ArtQuota> TreeToList(List<ArtQuota> trees, List<ArtQuota> nodes, string pid)
  52. {
  53. List<ArtQuota> list = new List<ArtQuota>();
  54. trees.ForEach(x => {
  55. var node = new ArtQuota
  56. {
  57. pid = string.IsNullOrWhiteSpace(pid) ? x.id : pid,
  58. id = x.id,
  59. name = x.name,
  60. percent = x.percent,
  61. type = x.type,
  62. };
  63. list.Add(node);
  64. });
  65. nodes.AddRange(list);
  66. foreach (ArtQuota tree in trees)
  67. {
  68. if (tree.children.IsNotEmpty())
  69. {
  70. TreeToList(tree.children, nodes, tree.id);
  71. }
  72. }
  73. return nodes;
  74. }
  75. public async static Task GenArtPDF (List<string> studentIds, string _artId, string _schoolId, string head_lang,AzureServiceBusFactory _serviceBus, IConfiguration _configuration)
  76. {
  77. var messageBlobPDF = new ServiceBusMessage(new { studentIds, artId= _artId, schoolCode = $"{_schoolId}", headLang= head_lang, bizType = "ArtStudentPdf" }.ToJsonString());
  78. var GenPdfQueue = _configuration.GetValue<string>("Azure:ServiceBus:GenPdfQueue");
  79. await _serviceBus.GetServiceBusClient().SendMessageAsync(GenPdfQueue, messageBlobPDF);
  80. }
  81. public async static Task<(List<ArtStudentPdf> studentPdfs, List<StudentArtResult> artResults)> GenStuArtPDF(List<string> studentIds, string _artId, ArtEvaluation art, string _schoolId,string head_lang ,AzureCosmosFactory _azureCosmos,
  82. CoreAPIHttpService _coreAPIHttpService, DingDing _dingDing) {
  83. var client = _azureCosmos.GetCosmosClient();
  84. string query = $" select value c from c where c.school = '{_schoolId}' ";
  85. if (studentIds.Any())
  86. {
  87. query = $" select value c from c where c.school = '{_schoolId}' and c.studentId in ({string.Join(",", studentIds.Select(z => $"'{z}'"))})";
  88. }
  89. List<StudentArtResult> artResults = new List<StudentArtResult>();
  90. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Student).GetItemQueryIteratorSql<StudentArtResult>
  91. (queryText: query, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"ArtResult-{_artId}") }))
  92. {
  93. artResults.Add(item);
  94. }
  95. School school = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>($"{_schoolId}", new PartitionKey("Base"));
  96. string path = Path.Combine("", $"Lang/{head_lang}.json");
  97. string comment1 = "";
  98. string comment2 = "";
  99. string comment3 = "";
  100. string comment4 = "";
  101. string comment5 = "";
  102. string comment_subject_music = "";
  103. string comment_subject_painting = "";
  104. var jsonDoc = readFileJson(path);
  105. if (jsonDoc != null)
  106. {
  107. if (jsonDoc.RootElement.TryGetProperty("art-template-comment1", out JsonElement _c1))
  108. {
  109. comment1 = $"{_c1}";
  110. }
  111. if (jsonDoc.RootElement.TryGetProperty("art-template-comment2", out JsonElement _c2))
  112. {
  113. comment2 = $"{_c2}";
  114. }
  115. if (jsonDoc.RootElement.TryGetProperty("art-template-comment3", out JsonElement _c3))
  116. {
  117. comment3 = $"{_c3}";
  118. }
  119. if (jsonDoc.RootElement.TryGetProperty("art-template-comment4", out JsonElement _c4))
  120. {
  121. comment4 = $"{_c4}";
  122. }
  123. if (jsonDoc.RootElement.TryGetProperty("art-template-comment5", out JsonElement _c5))
  124. {
  125. comment5 = $"{_c5}";
  126. }
  127. if (jsonDoc.RootElement.TryGetProperty("art-template-subject_music", out JsonElement _subject_music))
  128. {
  129. comment_subject_music = $"{_subject_music}";
  130. }
  131. if (jsonDoc.RootElement.TryGetProperty("art-template-subject_painting", out JsonElement _subject_painting))
  132. {
  133. comment_subject_painting = $"{_subject_painting}";
  134. }
  135. }
  136. ArtSetting artSetting = await client.GetContainer(Constant.TEAMModelOS, Constant.Normal).ReadItemAsync<ArtSetting>($"{school.areaId}", new PartitionKey($"ArtSetting"));
  137. var allExamIds = art.settings.SelectMany(x => x.task).Where(z => z.type == 1);
  138. var subjects = art.subjects;
  139. //获取学校的所有艺术科目的uuid,并映射找到相应的知识点,知识块。
  140. var schoolSubjects = school.period.SelectMany(x => x.subjects).Where(s => !string.IsNullOrWhiteSpace(s.bindId) && subjects.Select(z => z.id).Contains(s.bindId));
  141. StringBuilder sql = new StringBuilder($"select value(c) from c");
  142. List<KeyValuePair<string, List<Block>>> subjectBindBlocks = new List<KeyValuePair<string, List<Block>>>();
  143. foreach (var schSub in schoolSubjects)
  144. {
  145. List<Block> blocks = new List<Block>();
  146. string code = $"Knowledge-{_schoolId}-{schSub.id}";
  147. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School")
  148. .GetItemQueryIteratorSql<Knowledge>(queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
  149. {
  150. item.blocks.ForEach(x =>
  151. {
  152. var block = blocks.Find(z => z.name.Equals(x.name));
  153. if (block != null)
  154. {
  155. block.points.AddRange(x.points);
  156. }
  157. else
  158. {
  159. blocks.Add(x);
  160. }
  161. });
  162. }
  163. subjectBindBlocks.Add(new KeyValuePair<string, List<Block>>(schSub.bindId, blocks));
  164. }
  165. List<ExamInfo> exams = new List<ExamInfo>();
  166. List<ExamResult> examResults = new();
  167. if (allExamIds.Any())
  168. {
  169. var queryExam = $"select value c from c where c.id in ({string.Join(",", allExamIds.Select(x => $"'{x.acId}'"))}) ";
  170. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<ExamInfo>(queryText: queryExam, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Exam-{_schoolId}") }))
  171. {
  172. exams.Add(item);
  173. }
  174. foreach (var allexamId in allExamIds)
  175. {
  176. var queryResult = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.paper,c.classes,c.sRate,c.average,c.standard,c.lostStus,c.record,c.phc,c.plc,c.examId from c where c.examId = '{allexamId.acId}' and c.subjectId = '{allexamId.subject}' ";
  177. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<ExamResult>(queryText: queryResult, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamResult-{allexamId.acId}") }))
  178. {
  179. examResults.Add(item);
  180. }
  181. }
  182. }
  183. (List<RMember> rmembers, List<RGroupList> groups) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, art.classes, art.school);
  184. List<ArtStudentPdf> studentPdfs = new List<ArtStudentPdf>();
  185. artResults.ForEach(x =>
  186. {
  187. var allSubject = x.results.GroupBy(g => g.quotaId).Select(s => new { key = s.Key, list = s.ToList() }).ToList();
  188. var groupSubject = x.results.GroupBy(g => $"{g.quotaId}-{g.subjectId}").Select(s => new { key = s.Key, list = s.ToList() }).ToList();
  189. //综合-所有科目的艺术评测指标维度。
  190. List<ArtQuotaPdf> allSubjectArtQuotaPdfs = new List<ArtQuotaPdf>();
  191. allSubject.ForEach(a =>
  192. {
  193. ArtQuotaPdf artPdf = new ArtQuotaPdf();
  194. List<ArtQuota> parents = ArtService.GetParentByChildId(artSetting.quotas, $"{a.key}");
  195. parents.ForEach(x =>
  196. {
  197. switch (true)
  198. {
  199. case bool when x.level == 1:
  200. artPdf.quota1 = x.id;
  201. artPdf.quotaN1 = x.name;
  202. artPdf.quotaP1 = x.percent;
  203. if (a.key.Equals(x.id))
  204. {
  205. artPdf.quotaName = x.name;
  206. }
  207. break;
  208. case bool when x.level == 2:
  209. artPdf.quota2 = x.id;
  210. artPdf.quotaN2 = x.name;
  211. artPdf.quotaP2 = x.percent;
  212. if (a.key.Equals(x.id))
  213. {
  214. artPdf.quotaName = x.name;
  215. }
  216. break;
  217. case bool when x.level == 3:
  218. artPdf.quota3 = x.id;
  219. artPdf.quotaN3 = x.name;
  220. artPdf.quotaP3 = x.percent;
  221. if (a.key.Equals(x.id))
  222. {
  223. artPdf.quotaName = x.name;
  224. }
  225. break;
  226. }
  227. });
  228. var noneScore = a.list.FindAll(x => x.score == -1);
  229. if (!noneScore.IsNotEmpty())
  230. {
  231. //全部未打分。
  232. if (noneScore.Count >= art.subjects.Count)
  233. {
  234. artPdf.quotaId = a.key;
  235. artPdf.score = 0;
  236. artPdf.scoreData = "-";
  237. artPdf.percent = "0";
  238. }
  239. else
  240. {
  241. //有一部分打分的,只算有分的平均分。
  242. var hasScore = a.list.FindAll(x => x.score >= 0);
  243. if (hasScore.IsNotEmpty())
  244. {
  245. var avgScore = hasScore.Sum(x => x.score) * 1.0 / a.list.Count;
  246. var avg = decimal.Round(decimal.Parse($"{avgScore}"), 2);
  247. artPdf.quotaId = a.key;
  248. artPdf.score = double.Parse($"{avg}");
  249. artPdf.scoreData = $"{avg}";
  250. artPdf.percent = $"{avg}";
  251. }
  252. else
  253. {
  254. artPdf.quotaId = a.key;
  255. artPdf.score = 0;
  256. artPdf.scoreData = "-";
  257. artPdf.percent = "0";
  258. }
  259. }
  260. }
  261. else
  262. {
  263. artPdf.quotaId = a.key;
  264. artPdf.score = 0;
  265. artPdf.scoreData = "-";
  266. artPdf.percent = "0";
  267. }
  268. allSubjectArtQuotaPdfs.Add(artPdf);
  269. });
  270. string level = "";
  271. double allScore = 0;
  272. if (x.subjectScores.Any())
  273. {
  274. //allScore = allSubjectArtQuotaPdfs.Sum(a => a.score) / allSubjectArtQuotaPdfs.Count;
  275. // allScore = allSubjectArtQuotaPdfs.Sum(a => a.score) / allSubjectArtQuotaPdfs.Count;
  276. allScore=Math.Round(x.subjectScores.Sum(a => a.score)*1.0/ x.subjectScores.Count,2) ;
  277. foreach (var xs in x.subjectScores)
  278. {
  279. var slevel = string.Empty;
  280. if (xs.score >= 100)
  281. {
  282. slevel = "优秀(A+)";
  283. }
  284. if (xs.score <= 0)
  285. {
  286. slevel = "待及格(D)";
  287. }
  288. if (xs.score < 100)
  289. {
  290. artSetting.reviewLevel.ForEach(r =>
  291. {
  292. if (r.value[0] <= xs.score && r.value[1] > xs.score)
  293. {
  294. slevel = r.code;
  295. }
  296. });
  297. }
  298. xs.level = slevel;
  299. }
  300. }
  301. if (allScore >= 100)
  302. {
  303. allScore = 100;
  304. level = "优秀(A+)";
  305. }
  306. if (allScore <= 0)
  307. {
  308. allScore = 0;
  309. level = "待及格(D)";
  310. }
  311. if (allScore < 100)
  312. {
  313. artSetting.reviewLevel.ForEach(r =>
  314. {
  315. if (r.value[0] <= allScore && r.value[1] > allScore)
  316. {
  317. level = r.code;
  318. }
  319. });
  320. }
  321. var rmbs = rmembers.FindAll(r => r.id.Equals(x.studentId) && r.type == 2 && x.code.Equals(x.school));
  322. if (rmbs.IsNotEmpty())
  323. {
  324. x.studentName = rmbs[0].name;
  325. }
  326. List<string> classNames = new List<string>();
  327. HashSet<string> periodIds = new HashSet<string>();
  328. x.classIds.ForEach(c =>
  329. {
  330. var gps = groups.FindAll(g => g.id.Equals(c));
  331. if (gps.IsNotEmpty())
  332. {
  333. classNames.Add(gps[0].name);
  334. if (!string.IsNullOrWhiteSpace(gps[0].periodId))
  335. {
  336. periodIds.Add(gps[0].periodId);
  337. }
  338. }
  339. });
  340. allSubjectArtQuotaPdfs.ForEach(x => x.level = level);
  341. var allSubjectQuotas = allSubjectArtQuotaPdfs.OrderBy(o => o.quota1).ThenBy(o => o.quota2).ThenBy(o => o.quota3);
  342. StringBuilder comment = new StringBuilder();
  343. switch (true)
  344. {
  345. case bool when level.Contains("(A+)"):
  346. comment.Append(comment1.Replace("{studentName}", x.studentName).Replace("{level}", "表现优异"));
  347. break;
  348. case bool when level.Contains("(A)"):
  349. comment.Append(comment1.Replace("{studentName}", x.studentName).Replace("{level}", "表现优秀"));
  350. break;
  351. case bool when level.Contains("(B+)"):
  352. comment.Append(comment1.Replace("{studentName}", x.studentName).Replace("{level}", "表现优良"));
  353. break;
  354. case bool when level.Contains("(B)"):
  355. comment.Append(comment1.Replace("{studentName}", x.studentName).Replace("{level}", "表现良好"));
  356. break;
  357. case bool when level.Contains("(C+)"):
  358. comment.Append(comment1.Replace("{studentName}", x.studentName).Replace("{level}", "还需加强"));
  359. break;
  360. case bool when level.Contains("(C)"):
  361. comment.Append(comment1.Replace("{studentName}", x.studentName).Replace("{level}", "有待提高"));
  362. break;
  363. case bool when level.Contains("(D)"):
  364. comment.Append(comment1.Replace("{studentName}", x.studentName).Replace("{level}", "还需努力"));
  365. break;
  366. }
  367. var score80 = allSubjectArtQuotaPdfs.Where(x => x.score >= 80);
  368. if (score80.Any())
  369. {
  370. List<string> quota = new List<string>();
  371. var quota3s = score80.Where(c => !string.IsNullOrWhiteSpace(c.quota3)).Select(z => z.quotaN3);
  372. if (quota3s.Any())
  373. {
  374. quota.AddRange(quota3s);
  375. }
  376. var quota2s = score80.Where(c => string.IsNullOrWhiteSpace(c.quota3) && !string.IsNullOrWhiteSpace(c.quota2)).Select(z => z.quotaN2);
  377. if (quota2s.Any())
  378. {
  379. quota.AddRange(quota2s);
  380. }
  381. comment.Append(comment2.Replace("{quotasHigh}", string.Join("、", quota)));
  382. }
  383. var score60 = allSubjectArtQuotaPdfs.Where(x => x.score < 60);
  384. if (score60.Any())
  385. {
  386. List<string> quota = new List<string>();
  387. var quota3s = score60.Where(c => !string.IsNullOrWhiteSpace(c.quota3)).Select(z => z.quotaN3);
  388. if (quota3s.Any())
  389. {
  390. quota.AddRange(quota3s);
  391. }
  392. var quota2s = score60.Where(c => string.IsNullOrWhiteSpace(c.quota3) && !string.IsNullOrWhiteSpace(c.quota2)).Select(z => z.quotaN2);
  393. if (quota2s.Any())
  394. {
  395. quota.AddRange(quota2s);
  396. }
  397. comment.Append(comment3.Replace("{quotasLow}", string.Join("、", quota)));
  398. }
  399. string periodId = "";
  400. string periodName = "";
  401. if (periodIds.Any())
  402. {
  403. var ps = school.period.FindAll(x => periodIds.Contains(x.id));
  404. if (ps.Any())
  405. {
  406. periodName = String.Join(",", ps.Select(x => x.name));
  407. periodId = String.Join(",", ps.Select(x => x.id));
  408. }
  409. }
  410. List<ArtSubjectPdf> subjectPdfs = new List<ArtSubjectPdf>();
  411. exams.ForEach(exam => {
  412. var result = examResults.FindAll(e => e.examId.Equals(exam.id));
  413. if (result.Any())
  414. {
  415. var datas = DoKnowledgePoint(result.First(), exam, x.studentId);
  416. if (exam.subjects.Any())
  417. {
  418. ArtSubjectPdf artSubjectPdf = new ArtSubjectPdf()
  419. {
  420. subjectId = exam.subjects.First().id,
  421. subjectName = exam.subjects.First().name
  422. };
  423. datas.pointScores.Value.ForEach(k => {
  424. var artPointPdfs = GetBlockAndDimension(k.score, k.tscore, artSubjectPdf.subjectId, k.name, subjectBindBlocks, artSetting);
  425. artSubjectPdf.pointPdfs.AddRange(artPointPdfs);
  426. });
  427. var pointHigh = artSubjectPdf.pointPdfs.Where(z => z.percent >= 0.8).Select(z => z.point).ToHashSet();
  428. var pointLow = artSubjectPdf.pointPdfs.Where(z => z.percent < 0.6).Select(z => z.point).ToHashSet();
  429. StringBuilder comment = new StringBuilder();
  430. if (pointHigh.Any())
  431. {
  432. comment.Append(comment4.Replace("{pointHigh}", string.Join("、", pointHigh)));
  433. }
  434. if (pointLow.Any())
  435. {
  436. comment.Append(comment5.Replace("{pointLow}", string.Join("、", pointLow)));
  437. }
  438. string custom_comment = string.Empty;
  439. if (artSubjectPdf.subjectId.Equals("subject_music"))
  440. {
  441. comment.Append(comment_subject_music);
  442. var dbcomment= x.subjectScores.Find(d => d.subjectId.Equals("subject_music"));
  443. custom_comment=dbcomment?.comment;
  444. }
  445. if (artSubjectPdf.subjectId.Equals("subject_painting"))
  446. {
  447. comment.Append(comment_subject_painting);
  448. var dbcomment = x.subjectScores.Find(d => d.subjectId.Equals("subject_painting"));
  449. custom_comment=dbcomment?.comment;
  450. }
  451. artSubjectPdf.comment = string.IsNullOrWhiteSpace(custom_comment)? comment.ToString():custom_comment;
  452. subjectPdfs.Add(artSubjectPdf);
  453. }
  454. }
  455. });
  456. ArtStudentPdf studentPdf = new ArtStudentPdf
  457. {
  458. artId = art.id,
  459. schoolCode = school.id,
  460. schoolName = school.name,
  461. periodId = periodId,
  462. periodName = periodName,
  463. studentId = x.studentId,
  464. studentName = x.studentName,
  465. picture = x.picture,
  466. classNames = classNames,
  467. artName = art.name,
  468. level = level,
  469. score = allScore,
  470. allSubjectQuotas = allSubjectQuotas.ToList(),
  471. comment =string.IsNullOrWhiteSpace(x.comment) ? comment.ToString() : x.comment,
  472. subjectPdfs = subjectPdfs,
  473. subjectScores=x.subjectScores,
  474. results=x.results
  475. };
  476. studentPdfs.Add(studentPdf);
  477. });
  478. // _ = _httpTrigger.RequestHttpTrigger(new { studentPdfs = studentPdfs, artResults, schoolCode = $"{_schoolId}" }, _option.Location, "gen-art-pdf");
  479. return (studentPdfs, artResults);
  480. }
  481. private static JsonDocument readFileJson(string path)
  482. {
  483. var sampleJson = System.IO.File.ReadAllBytes(path).AsSpan();
  484. Utf8JsonReader reader = new Utf8JsonReader(sampleJson);
  485. if (JsonDocument.TryParseValue(ref reader, out JsonDocument jsonDoc))
  486. {
  487. return jsonDoc;
  488. }
  489. else
  490. {
  491. return null;
  492. }
  493. }
  494. //获取本次评测所有科目结算结果
  495. /* List<ExamResult> examResults = new();
  496. ExamInfo info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(examId.ToString(), new PartitionKey($"Exam-{code}"));
  497. var query = $"select c.id,c.name,c.subjectId,c.studentScores,c.studentIds,c.paper,c.classes,c.sRate,c.average,c.standard,c.lostStus,c.record,c.phc,c.plc from c where c.examId = '{examId}' and c.subjectId = '{subjectId}' ";
  498. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<ExamResult>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"ExamResult-{examId}") }))
  499. {
  500. examResults.Add(item);
  501. }*/
  502. private static (KeyValuePair<string, List<string>> knowledgeName,
  503. KeyValuePair<string, List<(string name, double score)>> pointScore,
  504. KeyValuePair<string, List<(string name, double score)>> pointTScore,
  505. KeyValuePair<string, List<(string name, double score, double tscore)>> pointScores) DoKnowledgePoint(ExamResult exam, ExamInfo info, string studentId)
  506. {
  507. HashSet<string> knowledge = new();
  508. List<double> point = new();
  509. List<List<double>> result = new();
  510. List<ClassRange> classes = new();
  511. //定位试卷信息
  512. int index = 0;
  513. foreach (ExamSubject subject in info.subjects)
  514. {
  515. if (subject.id.Equals(exam.subjectId))
  516. {
  517. break;
  518. }
  519. else
  520. {
  521. index++;
  522. }
  523. }
  524. if (info.papers[index].knowledge != null && info.papers[index].knowledge.Count > 0)
  525. {
  526. info.papers[index].knowledge.ForEach(k =>
  527. {
  528. k.ForEach(e =>
  529. {
  530. knowledge.Add(e);
  531. });
  532. });
  533. }
  534. else
  535. {
  536. return (default, default, default, default);
  537. }
  538. point = info.papers[index].point;
  539. result = exam.studentScores;
  540. classes = exam.classes;
  541. List<string> knowledgeName = new List<string>();
  542. foreach (string cla in knowledge)
  543. {
  544. knowledgeName.Add(cla);
  545. }
  546. for (int k = 0; k < knowledgeName.Count; k++)
  547. {
  548. if (null == knowledgeName[k])
  549. {
  550. knowledgeName.Remove(knowledgeName[k]);
  551. }
  552. }
  553. List<double> knowScore = new();
  554. //学生得分情况
  555. List<(string name, double score)> pointScore = new();
  556. List<(string name, double score)> pointTScore = new();
  557. List<(string name, double score, double tscore)> pointScores = new();
  558. for (int k = 0; k < knowledgeName.Count; k++)
  559. {
  560. double OnePoint = 0;
  561. List<string> itemNo = new();
  562. int n = 0;
  563. double scores = 0;
  564. info.papers[index].knowledge.ForEach(kno =>
  565. {
  566. if (kno.Contains(knowledgeName[k]))
  567. {
  568. var itemPersent = kno.Count > 0 ? 1 / Convert.ToDouble(kno.Count) : 0;
  569. OnePoint += point[n] * itemPersent;
  570. int stuIndex = exam.studentIds.IndexOf(studentId);
  571. if (exam.studentScores[stuIndex][n] > 0)
  572. {
  573. scores += exam.studentScores[stuIndex][n] * itemPersent;
  574. }
  575. }
  576. n++;
  577. });
  578. //单个知识点的配分
  579. pointScore.Add((knowledgeName[k], OnePoint));
  580. pointTScore.Add((knowledgeName[k], scores));
  581. pointScores.Add((knowledgeName[k], OnePoint, scores));
  582. }
  583. KeyValuePair<string, List<string>> key1 = new(exam.subjectId, knowledgeName);
  584. KeyValuePair<string, List<(string name, double score)>> key2 = new(exam.subjectId, pointScore);
  585. KeyValuePair<string, List<(string name, double score)>> key3 = new(exam.subjectId, pointTScore);
  586. KeyValuePair<string, List<(string name, double score, double tscore)>> key4 = new(exam.subjectId, pointScores);
  587. return (key1, key2, key3, key4);
  588. }
  589. private static List<ArtPointPdf> GetBlockAndDimension(double score, double tscore, string subjectId, string point, List<KeyValuePair<string, List<Block>>> subjectBindBlocks, ArtSetting artSetting)
  590. {
  591. var block = subjectBindBlocks.Find(z => z.Key.Equals(subjectId));
  592. List<ArtPointPdf> artPointPdfs = new List<ArtPointPdf>();
  593. if (!string.IsNullOrWhiteSpace(block.Key))
  594. {
  595. block.Value.ForEach(z => {
  596. if (z.points.Contains(point))
  597. {
  598. var dims = artSetting.dimensions.FindAll(m => m.blocks.Contains(z.name));
  599. if (dims.Any())
  600. {
  601. foreach (var dim in dims)
  602. {
  603. artPointPdfs.Add(
  604. new ArtPointPdf
  605. {
  606. dimension = dim.dimension,
  607. block = z.name,
  608. point = point,
  609. totalScore = score,
  610. score = tscore,
  611. percent = score > 0 ? tscore * 1.0 / score : 0,
  612. }
  613. );
  614. }
  615. }
  616. }
  617. });
  618. }
  619. return artPointPdfs;
  620. }
  621. }
  622. }