ArtService.cs 30 KB

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