JointService.cs 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  1. using Azure.Messaging.ServiceBus;
  2. using Azure.Storage.Blobs.Models;
  3. using Azure;
  4. using Microsoft.Azure.Cosmos;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Security.Cryptography;
  9. using System.Text;
  10. using System.Text.Json;
  11. using System.Threading.Tasks;
  12. using TEAMModelOS.SDK.DI;
  13. using TEAMModelOS.SDK.Extension;
  14. using TEAMModelOS.SDK.Models.Service.BI;
  15. using TEAMModelOS.SDK.Services;
  16. using static TEAMModelOS.SDK.Models.JointEventGroupBase;
  17. using Azure.Core;
  18. using Microsoft.Extensions.Configuration;
  19. using static TEAMModelOS.SDK.Models.JointEvent;
  20. using TEAMModelOS.SDK.Models.Dtos;
  21. namespace TEAMModelOS.SDK.Models.Service
  22. {
  23. public static class JointService
  24. {
  25. //取得JointExam生成Exam
  26. public static async Task GenerateExamFromJointExamAsync(CosmosClient client, AzureStorageFactory _azureStorage, AzureServiceBusFactory _serviceBus, CoreAPIHttpService _coreAPIHttpService, AzureRedisFactory _azureRedis, IConfiguration _configuration, DingDing _dingDing, JointExam jointExam, string creatorId)
  27. {
  28. try
  29. {
  30. long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  31. //取得JointExam
  32. List<JointEventClassBase> classes = new List<JointEventClassBase>();
  33. List<JointEventGroupBase> stuLists = new List<JointEventGroupBase>();
  34. //取得JointCourse ※examType == "custom" 之後再處理
  35. List<JointEventGroupDb> jointCourses = new List<JointEventGroupDb>();
  36. if (!jointExam.examType.Equals("custom")) //熱身賽:老師報名名單
  37. {
  38. string jointCourseSql = $"SELECT * FROM c WHERE c.jointEventId = '{jointExam.jointEventId}' AND c.jointGroupId = '{jointExam.jointGroupId}' AND ( IS_DEFINED(c.type) = false OR c.type = 'regular' )";
  39. if (!string.IsNullOrWhiteSpace(creatorId)) jointCourseSql += $" AND c.creatorId = '{creatorId}' ";
  40. await foreach (var item in client.GetContainer("TEAMModelOS", Constant.Teacher).GetItemQueryIteratorSql<JointEventGroupDb>(queryText: jointCourseSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"JointCourse") }))
  41. {
  42. jointCourses.Add(item);
  43. }
  44. }
  45. else //決賽:決賽名單
  46. {
  47. string jointCourseSql = $"SELECT * FROM c WHERE c.jointEventId = '{jointExam.jointEventId}' AND c.jointGroupId = '{jointExam.jointGroupId}' AND IS_DEFINED(c.type) = true AND c.type = 'custom' ";
  48. if (!string.IsNullOrWhiteSpace(creatorId)) jointCourseSql += $" AND c.creatorId = '{creatorId}' ";
  49. await foreach (var item in client.GetContainer("TEAMModelOS", Constant.Teacher).GetItemQueryIteratorSql<JointEventGroupDb>(queryText: jointCourseSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"JointCourse") }))
  50. {
  51. jointCourses.Add(item);
  52. }
  53. }
  54. //評量資料生成 ExamInfo actExamInfo ※一個課程一個Exam
  55. List<ExamInfo> examList = new List<ExamInfo>();
  56. foreach (JointEventGroupDb jointCourse in jointCourses)
  57. {
  58. string actExamCreatorId = jointCourse.creatorId;
  59. //個人課程
  60. if(jointCourse.scope.Equals("private"))
  61. {
  62. foreach (JointEventGroupCourse jointExamGroupCourse in jointCourse.courseLists)
  63. {
  64. string actExamCourseId = jointExamGroupCourse.courseId;
  65. string actExamCourseName = jointExamGroupCourse.courseName;
  66. //評量資料生成
  67. ExamInfo actExamInfo = new ExamInfo();
  68. ///取得已生成的Exam ※
  69. string examSql = $"SELECT DISTINCT c.id, c.source, c.name, c.jointExamId, c.subjects, c.stuLists, c.targets, c.papers, c.year, c.startTime, c.endTime, c.code, c.owner, c.scope, c.creatorId FROM c JOIN s IN c.subjects WHERE c.jointExamId = '{jointExam.id}' AND s.id = '{actExamCourseId}'";
  70. await foreach (var item in client.GetContainer("TEAMModelOS", Constant.Common).GetItemQueryIteratorSql<ExamInfo>(queryText: examSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Exam-{actExamCreatorId}") }))
  71. {
  72. actExamInfo = item;
  73. }
  74. ///尚無評量資料
  75. if (string.IsNullOrWhiteSpace(actExamInfo.id))
  76. {
  77. actExamInfo.code = $"Exam-{actExamCreatorId}";
  78. actExamInfo.owner = "teacher";
  79. actExamInfo.scope = jointCourse.scope;
  80. actExamInfo.creatorId = actExamCreatorId;
  81. actExamInfo.id = Guid.NewGuid().ToString();
  82. }
  83. actExamInfo.source = jointExam.source;
  84. actExamInfo.name = jointExam.name;
  85. actExamInfo.jointExamId = jointExam.id;
  86. actExamInfo.subjects = new List<ExamSubject>() { new ExamSubject() { id = actExamCourseId, name = actExamCourseName, classCount = jointExamGroupCourse.groupLists.Count } };
  87. ///評量stuLists
  88. foreach (JointEventGroupCourseGroup actGroup in jointExamGroupCourse.groupLists)
  89. {
  90. if(!actExamInfo.stuLists.Contains(actGroup.id))
  91. {
  92. actExamInfo.stuLists.Add(actGroup.id);
  93. }
  94. List<string> targetRow = new List<string>() { actExamCourseId, actGroup.id };
  95. var targetRowJson = JsonSerializer.SerializeToElement(targetRow);
  96. bool add = true;
  97. foreach(JsonElement target in actExamInfo.targets)
  98. {
  99. if(target.ToJsonString().Equals(targetRowJson.ToJsonString()))
  100. {
  101. add = false;
  102. break;
  103. }
  104. }
  105. if(add)
  106. {
  107. actExamInfo.targets.Add(targetRowJson);
  108. }
  109. }
  110. ///試卷
  111. actExamInfo.papers = Newtonsoft.Json.JsonConvert.DeserializeObject<List<PaperSimple>>(Newtonsoft.Json.JsonConvert.SerializeObject(jointExam.papers));
  112. ///時間
  113. actExamInfo.year = DateTimeOffset.UtcNow.Year;
  114. actExamInfo.startTime = jointExam.startTime;
  115. actExamInfo.endTime = jointExam.endTime;
  116. ///是否重複作答
  117. actExamInfo.overwriteDisable = (jointExam.examOverwrite.Equals(false)) ? true : false;
  118. ///(前端)是否可見 ※只有決賽不可見
  119. actExamInfo.jointVisiable = (jointExam.examType.Equals("custom")) ? false : true;
  120. ///cloudas ※只有決賽有cloudas
  121. actExamInfo.cloudas = (jointExam.examType.Equals("custom")) ? true : false;
  122. examList.Add(actExamInfo);
  123. }
  124. }
  125. //[待做] 學校班級
  126. }
  127. //生成評量
  128. if (examList.Count > 0)
  129. {
  130. foreach (ExamInfo exam in examList)
  131. {
  132. await GenerateExam(client, _azureStorage, _serviceBus, _coreAPIHttpService, _azureRedis, _configuration, _dingDing, jointExam, exam);
  133. }
  134. }
  135. }
  136. catch (Exception)
  137. {
  138. }
  139. }
  140. //生成評量(單)
  141. private static async Task<string> GenerateExam(CosmosClient client, AzureStorageFactory _azureStorage, AzureServiceBusFactory _serviceBus, CoreAPIHttpService _coreAPIHttpService, AzureRedisFactory _azureRedis, IConfiguration _configuration, DingDing _dingDing, JointExam jointExam, ExamInfo exam)
  142. {
  143. long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  144. string Result = string.Empty;
  145. exam.createTime = now;
  146. if (exam.startTime <= 0) exam.startTime = now;
  147. List<(string pId, List<string> gid)> ps = new();
  148. var group = exam.groupLists;
  149. if (group.Count > 0)
  150. {
  151. foreach (var keys in group)
  152. {
  153. foreach (KeyValuePair<string, List<string>> pp in keys)
  154. {
  155. ps.Add((pp.Key, pp.Value));
  156. }
  157. }
  158. }
  159. List<string> classes = ExamService.getClasses(exam.classes, exam.stuLists);
  160. (List<RMember> tchList, List<RGroupList> classLists) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, classes, exam.school, ps);
  161. exam.stuCount = tchList.Count;
  162. string mode = string.Empty;
  163. ResponseMessage response = null;
  164. if (string.IsNullOrEmpty(exam.id))
  165. {
  166. mode = "add";
  167. }
  168. else
  169. {
  170. response = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(exam.id, new PartitionKey($"{exam.code}"));
  171. if (response.StatusCode == System.Net.HttpStatusCode.OK) mode = "upd";
  172. else mode = "add";
  173. }
  174. //DB操作
  175. if (mode.Equals("add")) //新建
  176. {
  177. if (string.IsNullOrWhiteSpace(exam.id)) exam.id = Guid.NewGuid().ToString();
  178. exam.progress = (exam.startTime > now) ? "pending" : "going";
  179. var messageBlob = new ServiceBusMessage();
  180. if (exam.scope.Equals("school") && !string.IsNullOrWhiteSpace(exam.school))
  181. {
  182. exam.size = await _azureStorage.GetBlobContainerClient(exam.school).GetBlobsSize($"exam/{exam.id}");
  183. await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"exam", name = exam.school }, _serviceBus, _configuration, _azureRedis);
  184. }
  185. else
  186. {
  187. exam.size = await _azureStorage.GetBlobContainerClient(exam.creatorId).GetBlobsSize($"exam/{exam.id}");
  188. await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"exam", name = exam.creatorId }, _serviceBus, _configuration, _azureRedis);
  189. }
  190. int n = 0;
  191. List<string> sheetIds = new List<string>();
  192. foreach (PaperSimple simple in exam.papers)
  193. {
  194. simple.blob = $"/exam/{exam.id}/paper/{exam.subjects[n].id}";
  195. n++;
  196. simple.sheet = null;
  197. }
  198. exam = await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(exam, new PartitionKey($"{exam.code}"));
  199. await BIStats.SetTypeAddStats(client, _dingDing, exam.school, "Exam", 1);//BI统计增/减量
  200. }
  201. else if (response != null) //更新
  202. {
  203. using var json = await JsonDocument.ParseAsync(response.Content);
  204. ExamInfo info = json.ToObject<ExamInfo>();
  205. if (info.progress.Equals("going"))
  206. {
  207. Result = "活动正在进行中,无法修改";
  208. }
  209. var messageBlob = new ServiceBusMessage();
  210. if (exam.scope.Equals("school") && !string.IsNullOrWhiteSpace(exam.school))
  211. {
  212. exam.size = await _azureStorage.GetBlobContainerClient(exam.school).GetBlobsSize($"exam/{exam.id}");
  213. await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"exam", name = exam.school }, _serviceBus, _configuration, _azureRedis);
  214. }
  215. else
  216. {
  217. exam.size = await _azureStorage.GetBlobContainerClient(exam.creatorId).GetBlobsSize($"exam/{exam.id}");
  218. await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"exam", name = exam.creatorId }, _serviceBus, _configuration, _azureRedis);
  219. }
  220. exam.progress = info.progress;
  221. int n = 0;
  222. List<string> sheetIds = new List<string>();
  223. foreach (PaperSimple simple in exam.papers)
  224. {
  225. if (!string.IsNullOrEmpty(simple.subjectId))
  226. {
  227. simple.blob = $"/exam/{exam.id}/paper/{simple.subjectId}/{simple.id}";
  228. }
  229. else
  230. {
  231. simple.blob = $"/exam/{exam.id}/paper/{exam.subjects[n].id}";
  232. n++;
  233. }
  234. simple.sheet = null;
  235. }
  236. exam = await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(exam, exam.id, new PartitionKey($"{exam.code}"));
  237. }
  238. //Blob操作 ※取得試卷源(blob)、複製到評測紀錄下
  239. ///試卷源字典
  240. List<Dictionary<string, string>> sourcePaperInfo = new List<Dictionary<string, string>>();
  241. foreach (PaperSimple paperInfo in jointExam.papers)
  242. {
  243. string paperBlobPath = (!paperInfo.blob.EndsWith("/")) ? paperInfo.blob + "/" : paperInfo.blob;
  244. paperBlobPath = (paperInfo.blob.StartsWith("/")) ? paperBlobPath.Remove(0, 1) : paperBlobPath;
  245. sourcePaperInfo.Add(new Dictionary<string, string>() { { "id", paperInfo.id }, { "blob", paperBlobPath }, { "itemcount", paperInfo.point.Count.ToString() } });
  246. }
  247. bool paperDataCopyErrFlg = false; //試卷資料拷貝錯誤Flag true:拷貝錯誤
  248. //Blob拷貝程序
  249. int paperIndex = 0;
  250. foreach (Dictionary<string, string> sourcePaperInfoDic in sourcePaperInfo)
  251. {
  252. //拷貝源:Container => jointExam.creatorId Path:papers.blob
  253. //拷貝對象:Container => exam.creatorId, Path:exam/{exam.id}/paper/{exam.subjects[paperIndex].id}/
  254. string targetScope = exam.scope; //評測對象 school:校本班級 private:私人課程
  255. var sourceBlobContainer = _azureStorage.GetBlobContainerClient(jointExam.creatorId); //統測活動來源一定是個人
  256. var blobPrivateContainer = (targetScope.Equals("school")) ? _azureStorage.GetBlobContainerClient(exam.school) : _azureStorage.GetBlobContainerClient(exam.creatorId);
  257. string sourceBlobPath = sourcePaperInfoDic["blob"];
  258. string subjectId = exam.subjects[paperIndex].id;
  259. string destBlobPath = $"exam/{exam.id}/paper/{subjectId}/"; //拷貝對象路徑 path:exam/{評測ID}/paper/{subjectID}/
  260. Pageable<BlobItem> sourceBlobs = sourceBlobContainer.GetBlobs(prefix: sourceBlobPath);
  261. if (sourceBlobs.Count() > 0)
  262. {
  263. foreach (var blob in sourceBlobs)
  264. {
  265. var sourceFileBlob = sourceBlobContainer.GetBlobClient(blob.Name);
  266. if (sourceFileBlob.Exists())
  267. {
  268. var sourceFileUri = sourceBlobContainer.GetBlobClient(blob.Name).Uri;
  269. string fileName = blob.Name.Replace(sourceBlobPath, "");
  270. string destBlobFilePath = $"{destBlobPath}{fileName}";
  271. await blobPrivateContainer.GetBlobClient(destBlobFilePath).StartCopyFromUriAsync(sourceFileUri);
  272. }
  273. else
  274. {
  275. paperDataCopyErrFlg = true;
  276. }
  277. }
  278. }
  279. paperIndex++;
  280. }
  281. return Result;
  282. }
  283. //以JointSchedule為單位,判斷班級/課程名單是否完成並生成決賽名單
  284. /// <param name="mode">updDb true:更新DB false:不更新DB</param>
  285. /// <param name="classCnt"> 班級流水號 (此次活動參加的班級數)
  286. public static async Task<object> CreatePassJointCourseBySchedule(CosmosClient client, string jointEventId, string jointGroupId, string jointScheduleId, string scope, bool updDb, int classCnt)
  287. {
  288. List<JointEventGroupDb> result = new List<JointEventGroupDb>();
  289. //0. 取得jointEvent、JointEventSchedule
  290. JointEvent jointEvent = await client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<JointEvent>(jointEventId, new PartitionKey("JointEvent"));
  291. if (jointEvent == null)
  292. {
  293. return result;
  294. }
  295. JointEventSchedule jointEventSchedule = jointEvent.schedule.Where(s => s.id.Equals(jointScheduleId)).FirstOrDefault();
  296. if (jointEventSchedule == null)
  297. {
  298. return result;
  299. }
  300. //1. 用jointEventId、jointGroupId 取得所有老師報名的 班級/課程名單
  301. List<JointEventGroupDb> jointEventCourse = new List<JointEventGroupDb>();
  302. StringBuilder stringBuilderJointCourse = new($"SELECT * FROM c WHERE c.jointEventId = '{jointEventId}' AND c.jointGroupId = '{jointGroupId}' AND c.scope = '{scope}' AND (c.type = 'regular' OR NOT IS_DEFINED(c.type) OR IS_NULL(c.type)) ");
  303. string container = (scope.Equals("school")) ? Constant.School : Constant.Teacher;
  304. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, container).GetItemQueryStreamIteratorSql(queryText: stringBuilderJointCourse.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("JointCourse") }))
  305. {
  306. using var json = await JsonDocument.ParseAsync(item.Content);
  307. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  308. {
  309. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  310. {
  311. jointEventCourse.Add(obj.ToObject<JointEventGroupDb>());
  312. }
  313. }
  314. }
  315. //2. 取得本Schedule的所有JointExam
  316. List<string> jointExamIdList = new List<string>();
  317. List<JointExam> jointEventExam = new List<JointExam>();
  318. StringBuilder stringBuilderJointExam = new($"SELECT * FROM c WHERE c.jointEventId = '{jointEventId}' AND c.jointGroupId = '{jointGroupId}' AND c.jointScheduleId = '{jointScheduleId}' ");
  319. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Common).GetItemQueryStreamIteratorSql(queryText: stringBuilderJointExam.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("JointExam") }))
  320. {
  321. using var json = await JsonDocument.ParseAsync(item.Content);
  322. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  323. {
  324. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  325. {
  326. JointExam jointExamRow = obj.ToObject<JointExam>();
  327. jointEventExam.Add(jointExamRow);
  328. if (!jointExamIdList.Contains(jointExamRow.id))
  329. {
  330. jointExamIdList.Add(jointExamRow.id);
  331. }
  332. }
  333. }
  334. }
  335. //3. 取得所有JointExam關聯的Exam
  336. List<ExamInfo> exam = new List<ExamInfo>();
  337. StringBuilder stringBuilderExam = new($"SELECT * FROM c WHERE c.pk = 'Exam' AND ARRAY_CONTAINS({JsonSerializer.Serialize(jointExamIdList)}, c.jointExamId) ");
  338. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Common).GetItemQueryStreamIteratorSql(queryText: stringBuilderExam.ToString(), requestOptions: null))
  339. {
  340. using var json = await JsonDocument.ParseAsync(item.Content);
  341. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  342. {
  343. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  344. {
  345. exam.Add(obj.ToObject<ExamInfo>());
  346. }
  347. }
  348. }
  349. //4. 用 IfJointExamComplete 列出完成評量的 班級/課程名單
  350. List<JointEventGroupPassDto> passGroupsBindJointexam = new List<JointEventGroupPassDto>(); //已完成的課程名單和已完成的JointExam對照表
  351. JointEventSchedule finalSchedule = jointEvent.schedule.Where(s => s.type.Equals("exam") && s.examType.Equals("custom")).FirstOrDefault(); //取schedule中的決賽為jointScheduleId ※應該只會有一個決賽
  352. if (finalSchedule != null) //可取得挑戰賽才繼續
  353. {
  354. foreach (JointExam jointExamRow in jointEventExam)
  355. {
  356. ///第1層 JointExam
  357. List<ExamInfo> examsNow = exam.Where(e => e.jointExamId.Equals(jointExamRow.id)).ToList();
  358. foreach (JointEventGroupDb jointEventCourseRow in jointEventCourse)
  359. {
  360. ///第2層 jointEventCourse
  361. string creatorIdRow = jointEventCourseRow.creatorId;
  362. foreach (JointEventGroupBase.JointEventGroupCourse jointCourseIn in jointEventCourseRow.courseLists)
  363. {
  364. ///第3層 老師報名的course
  365. string courseId = jointCourseIn.courseId;
  366. string courseName = jointCourseIn.courseName;
  367. List<string> groupIds = jointCourseIn.groupLists.Select(c => c.id).ToList();
  368. ExamInfo examNow = examsNow.Where(e => e.creatorId.Equals(creatorIdRow) && e.subjects[0].id.Equals(courseId)).FirstOrDefault();
  369. if (examNow != null)
  370. {
  371. string examId = examNow.id;
  372. string schoolId = string.Empty;
  373. string classId = string.Empty;
  374. foreach (string groupId in groupIds)
  375. {
  376. JointEventGroupBase.JointEventGroupCourseGroup passGroupInfo = await IfExamComplete(client, examId, scope, creatorIdRow, schoolId, classId, groupId);
  377. if (passGroupInfo != null)
  378. {
  379. //生成決賽通過的老師課程名單用中間model
  380. JointEventGroupPassDto passGroupRow = passGroupsBindJointexam.Where(p => p.creatorId.Equals(jointEventCourseRow.creatorId) && p.courseId.Equals(courseId) && p.groupId.Equals(groupId)).FirstOrDefault();
  381. if (passGroupRow == null)
  382. {
  383. passGroupsBindJointexam.Add(new JointEventGroupPassDto()
  384. {
  385. creatorId = jointEventCourseRow.creatorId,
  386. courseId = courseId,
  387. groupId = groupId
  388. });
  389. passGroupRow = passGroupsBindJointexam.Where(p => p.creatorId.Equals(jointEventCourseRow.creatorId) && p.courseId.Equals(courseId) && p.groupId.Equals(groupId)).FirstOrDefault();
  390. }
  391. if (!passGroupRow.jointExamId.Contains(jointExamRow.id))
  392. {
  393. passGroupRow.jointExamId.Add(jointExamRow.id);
  394. }
  395. //if (passGroupRow.jointExamId.Count.Equals(jointExamIdList.Count)) //[舊] 所有評量都完成 => pass
  396. //{
  397. // passGroupRow.pass = true;
  398. //}
  399. if(passGroupRow.jointExamId.Count > 0) //[新] 有任一評量完成 => pass
  400. {
  401. passGroupRow.pass = true;
  402. }
  403. }
  404. }
  405. }
  406. }
  407. }
  408. }
  409. }
  410. //5. 決賽課程生成
  411. ///生成資料製作
  412. List<JointEventGroupDb> jointCourseCreates = new List<JointEventGroupDb>(); //要生成的老師課程名單
  413. foreach (JointEventGroupDb jointEventCourseRow in jointEventCourse)
  414. {
  415. foreach (JointEventGroupBase.JointEventGroupCourse course in jointEventCourseRow.courseLists)
  416. {
  417. foreach (JointEventGroupBase.JointEventGroupCourseGroup group in course.groupLists)
  418. {
  419. JointEventGroupPassDto passGroupRow = passGroupsBindJointexam.Where(g => g.creatorId.Equals(jointEventCourseRow.creatorId) && g.courseId.Equals(course.courseId) && g.groupId.Equals(group.id) && g.pass.Equals(true)).FirstOrDefault();
  420. if (passGroupRow != null)
  421. {
  422. string courseId = course.courseId;
  423. string courseName = course.courseName;
  424. JointEventGroupDb jointCourseCreateRow = jointCourseCreates.Where(c => c.jointEventId.Equals(jointEventCourseRow.jointEventId) && c.jointGroupId.Equals(jointEventCourseRow.jointGroupId) && c.creatorId.Equals(jointEventCourseRow.creatorId)).FirstOrDefault();
  425. if (jointCourseCreateRow == null)
  426. {
  427. ///DB 老師決賽document
  428. JointEventGroupDb finalEventCourse = new JointEventGroupDb();
  429. finalEventCourse.jointEventId = jointEventCourseRow.jointEventId;
  430. finalEventCourse.jointGroupId = jointEventCourseRow.jointGroupId;
  431. finalEventCourse.code = jointEventCourseRow.code;
  432. finalEventCourse.pk = jointEventCourseRow.pk;
  433. finalEventCourse.scope = jointEventCourseRow.scope;
  434. finalEventCourse.type = "custom"; //決賽
  435. finalEventCourse.creatorId = jointEventCourseRow.creatorId;
  436. finalEventCourse.creatorName = jointEventCourseRow.creatorName;
  437. finalEventCourse.creatorEmail = jointEventCourseRow.creatorEmail;
  438. finalEventCourse.schoolId = jointEventCourseRow.schoolId;
  439. finalEventCourse.schoolName = jointEventCourseRow.schoolName;
  440. finalEventCourse.countryId = jointEventCourseRow.countryId;
  441. finalEventCourse.countryName = jointEventCourseRow.countryName;
  442. finalEventCourse.provinceId = jointEventCourseRow.provinceId;
  443. finalEventCourse.provinceName = jointEventCourseRow.provinceName;
  444. finalEventCourse.cityId = jointEventCourseRow.cityId;
  445. finalEventCourse.cityName = jointEventCourseRow.cityName;
  446. finalEventCourse.jointScheduleId = finalSchedule.id;
  447. classCnt++;
  448. finalEventCourse.courseLists.Add(new JointEventGroupBase.JointEventGroupCourse()
  449. {
  450. courseId = courseId,
  451. courseName = courseName,
  452. groupLists = new List<JointEventGroupBase.JointEventGroupCourseGroup>() {
  453. new() { id = group.id, name = group.name, no = classCnt.ToString() }
  454. }
  455. });
  456. finalEventCourse.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  457. jointCourseCreates.Add(finalEventCourse);
  458. }
  459. else
  460. {
  461. JointEventGroupBase.JointEventGroupCourse courseRowNow = jointCourseCreateRow.courseLists.Where(c => c.courseId.Equals(courseId)).FirstOrDefault();
  462. if (courseRowNow == null)
  463. {
  464. ///DB 老師決賽課程資料
  465. classCnt++;
  466. jointCourseCreateRow.courseLists.Add(
  467. new JointEventGroupBase.JointEventGroupCourse
  468. {
  469. courseId = courseId,
  470. courseName = courseName,
  471. groupLists = new List<JointEventGroupBase.JointEventGroupCourseGroup>() {
  472. new() { id = group.id, name = group.name, no = classCnt.ToString() }
  473. }
  474. }
  475. );
  476. }
  477. else
  478. {
  479. JointEventGroupBase.JointEventGroupCourseGroup groupRowNow = courseRowNow.groupLists.Where(g => g.id.Equals(group.id)).FirstOrDefault();
  480. if (groupRowNow == null)
  481. {
  482. ///DB 老師決賽班級資料
  483. classCnt++;
  484. courseRowNow.groupLists.Add(
  485. new() { id = group.id, name = group.name, no = classCnt.ToString() }
  486. );
  487. }
  488. }
  489. }
  490. }
  491. }
  492. }
  493. }
  494. ///DB
  495. if (jointCourseCreates.Count > 0)
  496. {
  497. //取得所有已存在的決賽課程名單
  498. List<JointEventGroupDb> jointCourseFinalExist = new List<JointEventGroupDb>();
  499. StringBuilder stringBuilderJointCourseCreates = new($"SELECT * FROM c WHERE c.jointEventId = '{jointEventId}' AND c.jointGroupId = '{jointGroupId}' AND c.scope = '{scope}' AND c.type = 'custom' AND c.jointScheduleId = '{finalSchedule.id}' ");
  500. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, container).GetItemQueryStreamIteratorSql(queryText: stringBuilderJointCourseCreates.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("JointCourse") }))
  501. {
  502. using var json = await JsonDocument.ParseAsync(item.Content);
  503. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  504. {
  505. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  506. {
  507. jointCourseFinalExist.Add(obj.ToObject<JointEventGroupDb>());
  508. }
  509. }
  510. }
  511. //生成決賽課程名單
  512. foreach (JointEventGroupDb jointCourseCreateRow in jointCourseCreates)
  513. {
  514. JointEventGroupDb jointCourseFinalExistRow = jointCourseFinalExist.Where(j => j.creatorId.Equals(jointCourseCreateRow.creatorId)).FirstOrDefault();
  515. jointCourseCreateRow.id = (jointCourseFinalExistRow != null) ? jointCourseFinalExistRow.id : Guid.NewGuid().ToString();
  516. if(updDb)
  517. {
  518. await client.GetContainer(Constant.TEAMModelOS, container).UpsertItemAsync(jointCourseCreateRow);
  519. }
  520. result.Add(jointCourseCreateRow);
  521. }
  522. }
  523. return new { result = result, classCnt = classCnt };
  524. }
  525. //判斷某課程名單是否已完成評量
  526. //回傳值: 班級ID 或 課程名單ID 列表
  527. private static async Task<JointEventGroupCourseGroup> IfExamComplete(CosmosClient client, string examId, string scope, string creatorId, string school, string classId, string groupId)
  528. {
  529. JointEventGroupCourseGroup result = null;
  530. try
  531. {
  532. if (string.IsNullOrWhiteSpace(classId) && string.IsNullOrWhiteSpace(groupId)) return result;
  533. if ((scope.Equals("private") && string.IsNullOrWhiteSpace(creatorId)) || (scope.Equals("school") && string.IsNullOrWhiteSpace(school))) return result;
  534. string examClassResultCode = (scope.Equals("school") && !string.IsNullOrWhiteSpace(school)) ? $"ExamClassResult-{school}" : $"ExamClassResult-{creatorId}";
  535. StringBuilder stringBuilder = new($"SELECT c.info.id AS infoId, c.info.name AS infoName, c.studentIds, c.studentAnswers FROM c WHERE c.examId = '{examId}' ");
  536. if (!string.IsNullOrWhiteSpace(classId))
  537. {
  538. stringBuilder.Append($" AND c.info.id = '{classId}' ");
  539. }
  540. else
  541. {
  542. stringBuilder.Append($" AND c.info.id = '{groupId}' ");
  543. }
  544. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Common).GetItemQueryStreamIteratorSql(queryText: stringBuilder.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{examClassResultCode}") }))
  545. {
  546. using var json = await JsonDocument.ParseAsync(item.Content);
  547. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  548. {
  549. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  550. {
  551. string infoId = obj.GetProperty("infoId").GetString();
  552. string infoName = obj.GetProperty("infoName").GetString();
  553. List<string> studentIds = obj.GetProperty("studentIds").ToObject<List<string>>();
  554. List<List<string>> studentAnswers = obj.GetProperty("studentAnswers").ToObject<List<List<string>>>();
  555. bool hasAnswer = false;
  556. foreach (List<string> studentAnswer in studentAnswers)
  557. {
  558. if (studentAnswer.Count > 0)
  559. {
  560. hasAnswer = true;
  561. break;
  562. }
  563. }
  564. if (hasAnswer)
  565. {
  566. result = new JointEventGroupBase.JointEventGroupCourseGroup() { id = infoId, name = infoName };
  567. }
  568. }
  569. }
  570. }
  571. return result;
  572. }
  573. catch (Exception e)
  574. {
  575. return result;
  576. }
  577. }
  578. /// <summary>
  579. /// 計算統測活動各報名班級的各活動階段進行狀況
  580. /// </summary>
  581. /// <param name="jointEventId"></param>
  582. /// <param name="jointGroupId"></param>
  583. /// <param name="creatorId"></param>
  584. /// <param name="jointEventGroupDb">要取得的報名課程,若給null則會從DB取</param>
  585. /// <param name="schedule">若給null則所有schedule的status(報名、熱身賽、決賽)都計算</param>
  586. /// <param name="update">是否更新DB true:更新 false:不更新</param>
  587. public static async Task<JointEventGroupDb> CalJointCourseGroupScheduleStatusAsync(CosmosClient client, string jointEventId, string jointGroupId, string creatorId, JointEventGroupDb jointEventGroupDb = null, JointEventSchedule schedule = null)
  588. {
  589. long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  590. string scope = "private"; //先只指定個人
  591. string container = (scope.Equals("school")) ? Constant.School : Constant.Teacher;
  592. //取得統測活動
  593. JointEvent jointEvent = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<JointEvent>(jointEventId, new PartitionKey("JointEvent"));
  594. if (jointEvent == null)
  595. {
  596. return null;
  597. }
  598. //取得報名名單
  599. if (jointEventGroupDb == null)
  600. {
  601. StringBuilder stringBuilder = new($"SELECT * FROM c WHERE c.jointEventId = '{jointEventId}' AND c.jointGroupId = '{jointGroupId}' AND c.creatorId = '{creatorId}' AND c.type = 'regular' ");
  602. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, container).GetItemQueryStreamIteratorSql(queryText: stringBuilder.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("JointCourse") }))
  603. {
  604. using var json = await JsonDocument.ParseAsync(item.Content);
  605. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  606. {
  607. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  608. {
  609. jointEventGroupDb = obj.ToObject<JointEventGroupDb>();
  610. }
  611. }
  612. }
  613. }
  614. if (jointEventGroupDb == null)
  615. {
  616. return null;
  617. }
  618. //計算各階段Status
  619. List<JointEventSchedule> jointScheduleList = new List<JointEventSchedule>(); //要計算的活動階段
  620. if (schedule != null) jointScheduleList.Add(schedule);
  621. else jointScheduleList = jointEvent.schedule;
  622. ///計算邏輯
  623. foreach (JointEventGroupBase.JointEventGroupCourse courseRow in jointEventGroupDb.courseLists) //各報名課程
  624. {
  625. string courseId = courseRow.courseId;
  626. foreach (JointEventGroupBase.JointEventGroupCourseGroup courseGroup in courseRow.groupLists) //各報名課程名單(各班)
  627. {
  628. string groupId = courseGroup.id;
  629. foreach (JointEventSchedule eventSchedule in jointScheduleList) //各活動階段
  630. {
  631. //活動階段篩選:報名、熱身賽、決賽 才記入
  632. if(eventSchedule.type.Equals("join") || eventSchedule.type.Equals("exam"))
  633. {
  634. JointEventGroupBase.JointEventGroupCourseGroup.JointEventGroupCourseGroupSchedule courseGroupSchedule = courseGroup.schedule.FirstOrDefault(s => s.id.Equals(eventSchedule.id));
  635. if (courseGroupSchedule == null) //不存在 > 新建
  636. {
  637. courseGroupSchedule = new JointEventGroupBase.JointEventGroupCourseGroup.JointEventGroupCourseGroupSchedule()
  638. {
  639. id = eventSchedule.id,
  640. status = "undo"
  641. };
  642. courseGroup.schedule.Add(courseGroupSchedule);
  643. courseGroupSchedule = courseGroup.schedule.FirstOrDefault(s => s.id.Equals(eventSchedule.id));
  644. }
  645. courseGroupSchedule.status = await GetGroupJointScheduleStatus(client, jointEventId, jointGroupId, groupId, eventSchedule, jointEventGroupDb, creatorId);
  646. }
  647. }
  648. }
  649. }
  650. return jointEventGroupDb;
  651. }
  652. //判斷某groupId在某JointSchedule是否完成
  653. /// <summary>
  654. /// 判斷某groupId在某JointSchedule是否完成
  655. /// </summary>
  656. /// <param name="jointEventId"></param>
  657. /// <param name="jointGroupId"></param>
  658. /// <param name="groupId"></param>
  659. /// <param name="schedule"></param>
  660. /// <param name="jointCourse">統測報名班級DB document 若為null則由DB取</param>
  661. /// <param name="creatorId"></param>
  662. /// <returns></returns>
  663. private static async Task<string> GetGroupJointScheduleStatus(CosmosClient client, string jointEventId, string jointGroupId, string groupId, JointEventSchedule schedule, JointEventGroupDb jointCourse, string creatorId)
  664. {
  665. long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  666. string result = "undo";
  667. string scope = "private"; //先只指定個人
  668. string container = (scope.Equals("school")) ? Constant.School : Constant.Teacher;
  669. if (schedule.startTime <= now && now <= schedule.endTime) //活動階段在進行中才續行做Status判斷
  670. {
  671. switch (schedule.type)
  672. {
  673. //報名
  674. ///算出邏輯:(1)可取得該報名課程名單 -> complete (2)無法取得 -> undo
  675. case "join":
  676. if (jointCourse == null)
  677. {
  678. StringBuilder stringBuilderJointCourse = new($"SELECT * FROM c WHERE c.jointEventId = '{jointEventId}' AND c.jointGroupId = '{jointGroupId}' AND c.creatorId = '{creatorId}' AND c.type = 'regular' ");
  679. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, container).GetItemQueryStreamIteratorSql(queryText: stringBuilderJointCourse.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("JointCourse") }))
  680. {
  681. using var json = await JsonDocument.ParseAsync(item.Content);
  682. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  683. {
  684. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  685. {
  686. jointCourse = obj.ToObject<JointEventGroupDb>();
  687. }
  688. }
  689. }
  690. }
  691. if (jointCourse == null)
  692. {
  693. break;
  694. }
  695. foreach (JointEventGroupBase.JointEventGroupCourse courseInfo in jointCourse.courseLists)
  696. {
  697. JointEventGroupBase.JointEventGroupCourseGroup groupExist = courseInfo.groupLists.FirstOrDefault(g => g.id.Equals(groupId));
  698. if (groupExist != null)
  699. {
  700. result = "complete";
  701. }
  702. }
  703. break;
  704. //競賽
  705. ///算出邏輯: (1)無法取得報名班級(決賽班級) -> 資格不符(disqualify)
  706. /// (2)統測評量數 > 0 && 個人評量完成數(學生有一人有作答則是為完成) == 統測評量數 -> 完成(complete)
  707. /// (3)統測評量數 > 0 && 個人評量完成數 > 0 && 統測評量數 > 個人評量完成數 -> 進行中(doing)
  708. /// (4)default -> undo
  709. case "exam":
  710. //取得老師報名課程或決賽老師課程
  711. List<JointEventGroupDb> jointEventGroup = new List<JointEventGroupDb>(); //個人課程
  712. StringBuilder stringBuilderEventGroup = new($"SELECT * FROM c WHERE c.jointEventId = '{jointEventId}' AND c.jointGroupId = '{jointGroupId}' ");
  713. if (schedule.examType.Equals("regular")) //熱身賽
  714. {
  715. stringBuilderEventGroup.Append($" AND (c.type = 'regular' OR NOT IS_DEFINED(c.type) OR IS_NULL(c.type)) ");
  716. }
  717. else if (schedule.examType.Equals("custom")) //決賽
  718. {
  719. stringBuilderEventGroup.Append($" AND c.type = 'custom' AND c.jointScheduleId = '{schedule.id}' ");
  720. }
  721. if (!string.IsNullOrWhiteSpace(creatorId))
  722. {
  723. stringBuilderEventGroup.Append($" AND c.creatorId = '{creatorId}' ");
  724. }
  725. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryStreamIteratorSql(queryText: stringBuilderEventGroup.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("JointCourse") }))
  726. {
  727. using var json = await JsonDocument.ParseAsync(item.Content);
  728. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  729. {
  730. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  731. {
  732. jointEventGroup.Add(obj.ToObject<JointEventGroupDb>());
  733. }
  734. }
  735. }
  736. //取得本Schedule的所有JointExam
  737. List<string> jointExamIdList = new List<string>();
  738. StringBuilder stringBuilderJointExam = new($"SELECT DISTINCT VALUE c.id FROM c WHERE c.jointEventId = '{jointEventId}' AND c.jointGroupId = '{jointGroupId}' AND c.jointScheduleId = '{schedule.id}' ");
  739. var resultJointExam = await client.GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<string>(stringBuilderJointExam.ToString(), $"JointExam");
  740. if (resultJointExam.list.IsNotEmpty())
  741. {
  742. jointExamIdList = new List<string>(resultJointExam.list);
  743. }
  744. //取得所有個人評量
  745. List<string> examIdList = new List<string>();
  746. string sqlExam = $"SELECT DISTINCT VALUE c.id FROM c WHERE ARRAY_CONTAINS({JsonSerializer.Serialize(jointExamIdList)}, c.jointExamId) AND ARRAY_CONTAINS(c.stuLists, '{groupId}') AND CONTAINS(c.code, 'Exam-')";
  747. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Common).GetItemQueryIteratorSql<string>(queryText: sqlExam, requestOptions: new QueryRequestOptions { }))
  748. {
  749. examIdList.Add(item);
  750. }
  751. //取得所有考試的作答結果
  752. List<string> finishExamIdList = new List<string>();
  753. string sqlExamClassResult = $"SELECT c.examId, c.info.id as classId, c.studentAnswers FROM c WHERE ARRAY_CONTAINS({JsonSerializer.Serialize(examIdList)}, c.examId) AND c.info.id = '{groupId}' AND c.progress=true AND CONTAINS(c.code, 'ExamClassResult')";
  754. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Common).GetItemQueryStreamIteratorSql(queryText: sqlExamClassResult, requestOptions: new QueryRequestOptions() { }))
  755. {
  756. using var json = await JsonDocument.ParseAsync(item.Content);
  757. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  758. {
  759. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  760. {
  761. string examId = obj.GetProperty("examId").ToString();
  762. string classId = obj.GetProperty("classId").ToString();
  763. List<List<string>> studentAnswers = obj.GetProperty("studentAnswers").ToObject<List<List<string>>>();
  764. bool isFinish = false; //評量是否已完成 ※有任一學生有作答則視為已完成
  765. foreach (List<string> studentAnswer in studentAnswers)
  766. {
  767. if (studentAnswer.Count > 0) { isFinish = true; break; }
  768. }
  769. if (isFinish)
  770. {
  771. finishExamIdList.Add(examId);
  772. }
  773. }
  774. }
  775. }
  776. //結果判斷
  777. JointEventGroupBase.JointEventGroupCourseGroup classInGroup = new JointEventGroupBase.JointEventGroupCourseGroup(); //取得該班級的報名/決賽資訊
  778. foreach (JointEventGroupDb eventGroup in jointEventGroup)
  779. {
  780. foreach (JointEventGroupBase.JointEventGroupCourse eventCourse in eventGroup.courseLists)
  781. {
  782. foreach (JointEventGroupBase.JointEventGroupCourseGroup group in eventCourse.groupLists)
  783. {
  784. if (group.id.Equals(groupId))
  785. {
  786. classInGroup = group;
  787. }
  788. }
  789. }
  790. }
  791. if (jointEventGroup.Count.Equals(0) || string.IsNullOrWhiteSpace(classInGroup.id)) //資格不符
  792. {
  793. result = "disqualify";
  794. }
  795. else if (jointExamIdList.Count > 0 && jointExamIdList.Count.Equals(finishExamIdList.Count))
  796. {
  797. result = "complete";
  798. }
  799. else if (jointExamIdList.Count > 0 && finishExamIdList.Count > 0 && jointExamIdList.Count > finishExamIdList.Count)
  800. {
  801. result = "doing";
  802. }
  803. break;
  804. }
  805. }
  806. return result;
  807. }
  808. /// <summary>
  809. /// 計算決賽通過的老師課程名單用中間model
  810. /// </summary>
  811. public class JointEventGroupPassDto
  812. {
  813. public string creatorId { get; set; }
  814. public string courseId { get; set; }
  815. public string groupId { get; set; }
  816. public bool pass { get; set; }
  817. public List<string> jointExamId { get; set; } = new(); //已完成的活動評量ID
  818. }
  819. }
  820. }