123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624 |
- using Microsoft.Azure.Cosmos;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using System;
- using System.Collections.Generic;
- using System.IdentityModel.Tokens.Jwt;
- using System.Linq;
- using System.Text;
- using System.Text.Json;
- using System.Threading.Tasks;
- using TEAMModelOS.Models.Dto;
- using TEAMModelOS.SDK.Models;
- using TEAMModelOS.SDK;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Extension;
- using TEAMModelOS.SDK.Helper.Common.StringHelper;
- using TEAMModelOS.Models;
- using Microsoft.Extensions.Options;
- using TEAMModelOS.SDK.Models.Cosmos;
- using Microsoft.AspNetCore.Authorization;
- using TEAMModelOS.Filter;
- using StackExchange.Redis;
- using TEAMModelOS.SDK.Models.Cosmos.Inner;
- using System.IO;
- using System.Dynamic;
- using Azure.Storage.Blobs.Models;
- using Azure.Storage.Sas;
- using Lib.AspNetCore.ServerSentEvents;
- using TEAMModelOS.SDK.Models.Cosmos;
-
- using TEAMModelOS.SDK.Models.Service;
- namespace TEAMModelOS.Controllers.Core
- {
- [ProducesResponseType(StatusCodes.Status200OK)]
- [ProducesResponseType(StatusCodes.Status400BadRequest)]
- [Authorize(Roles = "HiTool,HiTools")]
- [Route("hiscan")]
- [ApiController]
- public class HiScanController : ControllerBase
- {
- private readonly AzureRedisFactory _azureRedis;
- private readonly AzureCosmosFactory _azureCosmos;
- private readonly SnowflakeId _snowflakeId;
- private readonly AzureServiceBusFactory _serviceBus;
- private readonly DingDing _dingDing;
- private readonly Option _option;
- private readonly AzureStorageFactory _azureStorage;
- // private readonly ServerSentEventsService _sse;
- private readonly CoreAPIHttpService _coreAPIHttpService;
- private readonly IPSearcher _searcher;
- private readonly HttpTrigger _httpTrigger;
- public HiScanController(CoreAPIHttpService coreAPIHttpService, AzureCosmosFactory azureCosmos, AzureServiceBusFactory serviceBus, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option,
- AzureRedisFactory azureRedis, AzureStorageFactory azureStorage, IPSearcher searcher, HttpTrigger httpTrigger//, ServerSentEventsService sse
- )
- {
- _azureCosmos = azureCosmos;
- _serviceBus = serviceBus;
- _snowflakeId = snowflakeId;
- _dingDing = dingDing;
- _option = option?.Value;
- _azureRedis = azureRedis;
- _coreAPIHttpService = coreAPIHttpService;
- _azureStorage = azureStorage;
- _searcher = searcher;
- _httpTrigger = httpTrigger;
- //_sse = sse;
- }
- ///<summary>
- ///查询教师的阅卷任务列表
- /// </summary>
- /// <data>
- /// ! "code":"tmdid"
- /// </data>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-schoolinfo")]
- // [AuthToken(Roles = "teacher,admin")]
- public async Task<IActionResult> GetSchoolinfo(JsonElement request)
- {
- List<dynamic> schools = new List<dynamic>();
- (string ip, string region) = await LoginService.LoginIp(HttpContext, _searcher);
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- try
- {
- Teacher response = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>($"{id}", new PartitionKey("Base"));
- string name = response.name;
- string picture = response.picture;
- foreach (var obj in response.schools)
- {
- string statusNow = obj.status;
- //正式加入才会有
- if (statusNow.Equals("join"))
- {
- try
- {
- //dynamic schoolExtobj = new ExpandoObject();
- School schoolJson = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{obj.schoolId}", new PartitionKey("Base"));
- var schoolId = obj.schoolId;
- var schoolName = schoolJson.name;
- var schoolPicture = schoolJson.picture;
- //检查学校购买的模组是否包含阅卷模组,暂不检查
- //int count = 0;
- //string sql = $" SELECT value(count(product)) FROM c join product in c.service.product where c.id ='{schoolId}' and c.pk='Product' and product.prodCode='YMPCVCIM' ";
- //await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIteratorSql<int>(sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Product") }))
- //{
- // count = item;
- //}
- //if (count > 0)
- //{
- // schools.Add(new { name = $"{schoolName}", picture = $"{schoolPicture}", id = $"{schoolId}" });
- //}
- schools.Add(new { name = $"{schoolName}", picture = $"{schoolPicture}", id = $"{schoolId}" });
- }
- catch { continue; }
- }
- }
- //用户在线记录
- //try
- //{
- // _ = _httpTrigger.RequestHttpTrigger(new { school = response.defaultSchool, scope = Constant.ScopeTeacher, id = $"{id}", ip = ip, expire = 1 }, _option.Location, "online-record");
- //}
- //catch { }
- var (tblob_uri, tblob_sas) = _azureStorage.GetBlobContainerSAS($"{id}", BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Delete);
- return Ok(new { schools, teacher = new { name, picture, id, bloburl = tblob_uri, blobsas = tblob_sas } });
- }
- catch (CosmosException ex) when (ex.StatusCode == System.Net.HttpStatusCode.NotFound)
- {
- return Ok(new {error= 1,msg="账号未再IES5使用"});
- }
- catch (Exception ex) {
- return BadRequest();
- }
- }
- ///<summary>
- ///查询教师的阅卷任务列表
- /// </summary>
- /// <data>
- /// ! "code":"tmdid"
- /// </data>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-examinfo")]
- // [AuthToken(Roles = "teacher,admin")]
- public async Task<IActionResult> GetExaminfo(JsonElement request)
- {
- try
- {
- List<SheetConfig> configs = new List<SheetConfig>();
- HashSet<string> classesSet = new HashSet<string>();
- List<ExamRcd> sexamRcds = new List<ExamRcd>();
- List<ExamRcd> psexamRcds = new List<ExamRcd>();
- List<ExamRcd> ppexamRcds = new List<ExamRcd>();
- List<ExamRcd> pexamRcds = new List<ExamRcd>();
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!request.TryGetProperty("schoolId", out JsonElement _schoolId)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- School school = null;
- try
- {
- school = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{_schoolId}", new PartitionKey("Base"));
- }
- catch (CosmosException ex)
- {
- if (ex.StatusCode == System.Net.HttpStatusCode.NotFound)
- {
- school = null;
- }
- }
- var response = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemStreamAsync($"{id}", new PartitionKey("Base"));
- if (school != null)
- {
- //检查学校购买的模组是否包含阅卷模组
- int count = 0;
- string sql = $" SELECT value(count(product)) FROM c join product in c.service.product where c.id ='{_schoolId}' and c.pk='Product' and product.prodCode='YMPCVCIM' ";
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIteratorSql<int>(sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Product") }))
- {
- count = item;
- }
- if (count > 0)
- {
- //获取学校线下阅卷评测
- sexamRcds = await GetExam("school", $"{_schoolId}", $"{_schoolId}", client, configs, classesSet);
- }
- if (response.StatusCode==System.Net.HttpStatusCode.OK)
- {
- //获取scope=school
- psexamRcds = await GetExam("school", $"{_schoolId}", $"{id}", client, configs, classesSet);
- if (psexamRcds.IsNotEmpty())
- {
- pexamRcds.AddRange(psexamRcds);
- }
- }
- }
- if (response.StatusCode==System.Net.HttpStatusCode.OK)
- {
- //获取scope=private
- ppexamRcds = await GetExam("private", null, $"{id}", client, configs, classesSet);
- if (ppexamRcds.IsNotEmpty())
- {
- pexamRcds.AddRange(ppexamRcds);
- }
- }
- (List<RMember> tmdIds, List<RGroupList> classInfo) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, classesSet.ToList(), $"{_schoolId}");
- /*var addStudentsCls = tmdIds.FindAll(x => x.type == 2);
- var addTmdidsCls = tmdIds.FindAll(x => x.type == 1);*/
- List<SheetConfig> configsN = new List<SheetConfig>();
- foreach (var config in configs)
- {
- if (config.scope.Equals("school"))
- {
- try
- {
- SheetConfig con = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<SheetConfig>(config.id, new PartitionKey(config.code));
- configsN.Add(con);
- }
- catch (CosmosException ex) { }
- }
- else
- {
- try
- {
- SheetConfig con = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<SheetConfig>(config.id, new PartitionKey(config.code));
- configsN.Add(con);
- }
- catch (CosmosException ex) { }
- }
- }
- //处理学校发布的评测
- if (sexamRcds.IsNotEmpty())
- {
- sexamRcds.SelectMany(y => y.classes).ToList().ForEach(z => {
- var a = classInfo.Where(m => m.id.Equals(z.id)).FirstOrDefault();
- if (a != null)
- {
- z.name = a.name;
- z.members = a.members;
- //z.tmdInfos = a.members.FindAll(x => x.type == 1);
- }
- });
- sexamRcds.SelectMany(y => y.papers).ToList().ForEach(z => {
- if (z.sheet != null)
- {
- var a = configsN.Where(m => m.id == z.sheet.id).FirstOrDefault();
- if (a != null)
- {
- z.sheet = a;
- }
- }
- });
- }
- //处理教师发布的个人班级评测和学校班级评测
- if (pexamRcds.IsNotEmpty())
- {
- pexamRcds.SelectMany(y => y.classes).ToList().ForEach(z => {
- var a = classInfo.Where(m => m.id == z.id).FirstOrDefault();
- if (a != null)
- {
- z.name = a.name;
- z.members = a.members;
- // z.members = a.tmdInfos;
- }
- });
- pexamRcds.SelectMany(y => y.papers).ToList().ForEach(z => {
- if (z.sheet != null)
- {
- var a = configsN.Where(m => m.id == z.sheet.id).FirstOrDefault();
- if (a != null)
- {
- z.sheet = a;
- }
- }
- });
- }
- string teacherBlobSas = null;
- string teacherBlobUrl = null;
- string schoolBlobSas = null;
- string schoolBlobUrl = null;
- if (ppexamRcds.IsNotEmpty())
- {
- var (tblob_uri, tblob_sas) = _azureStorage.GetBlobContainerSAS($"{id}", BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List);
- teacherBlobUrl = tblob_uri;
- teacherBlobSas = tblob_sas;
- }
- if (psexamRcds.IsNotEmpty() || sexamRcds.IsNotEmpty())
- {
- var (sblob_uri, sblob_sas) = _azureStorage.GetBlobContainerSAS(school.id, BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Write);
- schoolBlobUrl = sblob_uri;
- schoolBlobSas = sblob_sas;
- }
- return Ok(new { teacherBlobSas, teacherBlobUrl, schoolBlobSas, schoolBlobUrl, school = sexamRcds.IsNotEmpty() ? sexamRcds : null, teacher = pexamRcds.IsNotEmpty() ? pexamRcds : null });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"IES5,{_option.Location},hiscan/verify-qrcode()\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- private async Task<List<ExamRcd>> GetExam(string scope, string school, string code, CosmosClient client, List<SheetConfig> sheet, HashSet<string> classesSet)
- {
- List<ExamRcd> examRcds = new List<ExamRcd>();
- int i = 1;
- StringBuilder sql = new StringBuilder($"SELECT * FROM c where (c.status<>404 or IS_DEFINED(c.status) = false ) and (c.progress='going' or c.progress='finish') and c.scope='{scope}' ");
- if (!string.IsNullOrEmpty(school))
- {
- sql.Append($" and c.school='{school}' ");
- }
- //await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<Correct>(queryText: "SELECT * FROM c where c.source='2' and c.progress='going' order by c.createTime ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Correct-{code}") }))
- await foreach (var exam in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<ExamInfo>(queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Exam-{code}") }))
- {
- List<RGroupList> classes = new List<RGroupList>();
- if (exam.classes.IsNotEmpty())
- {
- exam.classes.ForEach(x => { classes.Add(new RGroupList { id = x }); classesSet.Add(x); });
- }
- if (exam.stuLists.IsNotEmpty())
- {
- exam.stuLists.ForEach(x => { classes.Add(new RGroupList { id = x }); classesSet.Add(x); });
- }
- List<PaperRcd> dys = new List<PaperRcd>();
- foreach (var pap in exam.papers)
- {
- if (!string.IsNullOrEmpty(pap.sheet))
- {
- if (exam.scope.Equals("school"))
- {
- SheetConfig config = new SheetConfig { id = pap.sheet, no = pap.sheetNo, scope = exam.scope, mode = pap.mode, code = $"SheetConfig-{exam.school}" };
- dys.Add(new PaperRcd { name = pap.name, answers = pap.answers, point = pap.point, sheet = config });
- sheet.Add(config);
- }
- else
- {
- SheetConfig config = new SheetConfig { id = pap.sheet, no = pap.sheetNo, scope = exam.scope,mode=pap.mode , code = $"SheetConfig-{code}" };
- dys.Add(new PaperRcd { name = pap.name, answers = pap.answers, point = pap.point, sheet = config });
- sheet.Add(config);
- }
- }
- else
- {
- dys.Add(new PaperRcd { name = pap.name, answers = pap.answers, point = pap.point, sheet = null });
- }
- }
- examRcds.Add(new ExamRcd
- {
- id = exam.id,
- name = exam.name,
- startTime = exam.startTime,
- endTime = exam.endTime,
- period = exam.period,
- grades = exam.grades,
- subjects = exam.subjects,
- papers = dys,
- classes = classes,
- scope = exam.scope
- });
- }
- return examRcds;
- }
- ///<summary>
- ///查询教师的阅卷任务列表
- /// </summary>
- /// <data>
- /// ! "code":"tmdid"
- /// </data>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-exam-by-sheet")]
- // [AuthToken(Roles = "teacher,admin")]
- public async Task<IActionResult> GetExamBySheet(JsonElement request)
- {
- try
- {
- HashSet<string> classesSet = new HashSet<string>();
- ExamSheetData examData = null;
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!request.TryGetProperty("schoolId", out JsonElement _schoolId)) return BadRequest();
- if (!request.TryGetProperty("sheetNo", out JsonElement _sheetNo)) return BadRequest();
- string _owner = (request.TryGetProperty("owner", out JsonElement _ownerJ)) ? _ownerJ.ToString() : string.Empty;
- string _scope = (request.TryGetProperty("scope", out JsonElement _scopeJ)) ? _scopeJ.ToString() : string.Empty;
- if (string.IsNullOrEmpty(_owner) && string.IsNullOrEmpty(_scope)) return BadRequest();
- else if (string.IsNullOrEmpty(_owner) && !string.IsNullOrEmpty(_scope)) _owner = _scope;
- var client = _azureCosmos.GetCosmosClient();
- School school = null;
- school = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{_schoolId}", new PartitionKey("Base"));
- if (school == null) return BadRequest();
- if ($"{_owner}".Equals("school", StringComparison.OrdinalIgnoreCase))
- {
- examData = await GetExamBySheet($"{_owner}", $"{_schoolId}", $"{_schoolId}", client, classesSet, $"{_sheetNo}");
- }
- else {
- var response = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemStreamAsync($"{id}", new PartitionKey("Base"));
- examData = await GetExamBySheet($"{_owner}", null, $"{id}", client, classesSet, $"{_sheetNo}");
-
- if (examData == null && string.IsNullOrEmpty($"{_schoolId}")) {
- examData = await GetExamBySheet($"{_owner}", $"{_schoolId}", $"{id}", client, classesSet, $"{_sheetNo}");
- }
- }
-
- (List<RMember> tmdIds, List<RGroupList> classInfo) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, classesSet.ToList(), $"{_schoolId}");
- List<SheetConfig> configsN = new List<SheetConfig>();
- if (examData.sheet != null) {
- if (examData.sheet.scope.Equals("school"))
- {
- ResponseMessage azure = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(examData.sheet.id, new PartitionKey(examData.sheet.code));
- if (azure.StatusCode ==System.Net.HttpStatusCode.OK && azure.Content!=null )
- {
- SheetConfig config = JsonDocument.Parse(azure.Content).RootElement.Deserialize<SheetConfig>();
- if (config != null)
- {
- configsN.Add(config);
- }
-
- }
- }
- else
- {
- ResponseMessage azure = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemStreamAsync(examData.sheet.id, new PartitionKey(examData.sheet.code));
- if (azure.StatusCode ==System.Net.HttpStatusCode.OK && azure.Content != null)
- {
- SheetConfig config = JsonDocument.Parse(azure.Content).RootElement.Deserialize<SheetConfig>();
- if (config != null)
- {
- configsN.Add(config);
- }
- }
- }
- }
- if (examData != null)
- {
- examData.classes.ForEach(z => {
- var a = classInfo.Where(m => m.id.Equals(z.id)).FirstOrDefault();
- if (a != null)
- {
- z.no=a.no;
- z.creatorId=a.creatorId;
- z.year=a.year;
- z.expire=a.expire;
- z.tcount=a.tcount;
- z.scount=a.scount;
- z.periodId = a.periodId;
- z.scope = a.scope;
- z.school = a.school;
- z.code = a.code;
- z.name = a.name;
- z.members = a.members;
- //z.tmdInfos = a.tmdInfos;
- }
- });
- if (examData.sheet!=null) {
- var a = configsN.Where(m => m.id == examData.sheet.id && m.scope.Equals(examData.sheet.scope)).FirstOrDefault();
- if (a != null)
- {
- examData.sheet = a;
- }
- }
- }
- string blobSas = null;
- string blobUrl = null;
- ExamSheetData exam = null;
- if (examData.sheet.scope.Equals("school", StringComparison.OrdinalIgnoreCase))
- {
- if (examData != null)
- {
- var (sblob_uri, sblob_sas) = _azureStorage.GetBlobContainerSAS(school.id, BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Write);
- blobUrl = sblob_uri;
- blobSas = sblob_sas;
- exam = examData;
- }
- }
- else {
- if (examData != null)
- {
- var (tblob_uri, tblob_sas) = _azureStorage.GetBlobContainerSAS($"{id}", BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List);
- blobUrl = tblob_uri;
- blobSas = tblob_sas;
- exam = examData;
- }
- }
- return Ok(new { blobUrl, blobSas, exam});
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"IES5,{_option.Location},get-exam-by-sheet\n{ex.Message}\n{ex.StackTrace}{request.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- private async Task<ExamSheetData> GetExamBySheet(string owner, string school, string code, CosmosClient client,HashSet<string> classesSet, string sheetNo)
- {
- ExamSheetData examRcds = null;
-
- StringBuilder sql = new StringBuilder($"SELECT value(c) FROM c join papers in c.papers where (c.status<>404 or IS_DEFINED(c.status) = false ) and c.owner='{owner}' and papers.sheetNo='{sheetNo}' ");
- if (!string.IsNullOrEmpty(school))
- {
- sql.Append($" and c.school='{school}' ");
- }
- //await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<Correct>(queryText: "SELECT * FROM c where c.source='2' and c.progress='going' order by c.createTime ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Correct-{code}") }))
- await foreach (var exam in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIteratorSql<ExamInfo>(queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Exam-{code}") }))
- {
- List<RGroupList> classes = new List<RGroupList>();
- if (exam.classes.IsNotEmpty())
- {
- exam.classes.ForEach(x => { classes.Add(new RGroupList { id = x }); classesSet.Add(x); });
- }
- if (exam.stuLists.IsNotEmpty())
- {
- exam.stuLists.ForEach(x => { classes.Add(new RGroupList { id = x }); classesSet.Add(x); });
- }
- PaperRcdData paper = null;
- ExamSubjectData subjectData = null;
- PaperSimple pap = exam.papers.Find(x => x.sheetNo == sheetNo);
- if (pap != null) {
- int index = exam.papers.FindIndex(x => x.sheetNo == sheetNo);
- ExamSubject subject = exam.subjects[index];
- subjectData = new ExamSubjectData { id = subject.id, name = subject.name };
- }
- SheetConfig config = null;
- if (!string.IsNullOrEmpty(pap.sheet))
- {
- if (exam.scope.Equals("school"))
- {
- config = new SheetConfig { id = pap.sheet, scope = exam.scope, mode = pap.mode, no = pap.sheetNo, code = $"SheetConfig-{exam.school}" };
- paper = new PaperRcdData { name = pap.name, answers = pap.answers, point = pap.point };
- }
- else
- {
- config = new SheetConfig { id = pap.sheet, scope = exam.scope, mode = pap.mode,no=pap.sheetNo, code = $"SheetConfig-{code}" };
- paper = new PaperRcdData { name = pap.name, answers = pap.answers, point = pap.point };
- }
- }
- else
- {
- paper = new PaperRcdData { name = pap.name, answers = pap.answers, point = pap.point, };
- }
- examRcds = new ExamSheetData
- {
- code = exam.code.Replace("Exam-", ""),
- id = exam.id,
- name = exam.name,
- startTime = exam.startTime,
- endTime = exam.endTime,
- period = exam.period,
- grades = exam.grades,
- subject = subjectData,
- paper = paper,
- classes = classes,
- scope = exam.scope,
- sheet = config
- };
- }
- return examRcds;
- }
- }
- public record PaperRcdData
- {
- public string name { get; set; }
- public List<List<string>> answers { get; set; } = new List<List<string>>();
- public List<double> point { get; set; } = new List<double>();
- }
- public record PaperRcd
- {
- public string name { get; set; }
- public List<List<string>> answers { get; set; } = new List<List<string>>();
- public List<double> point { get; set; } = new List<double>();
- public SheetConfig sheet { get; set; }
- }
- public class ExamSubjectData
- {
- public string id { get; set; }
- public string name { get; set; }
- }
- public record ExamSheetData
- {
- public string code { get; set; }
- public SheetConfig sheet { get; set; }
- public string id { get; set; }
- public string name { get; set; }
- public long startTime { get; set; }
- public long endTime { get; set; }
- public PeriodSimple period { get; set; }
- public List<Grade> grades { get; set; }
- public ExamSubjectData subject { get; set; }
- public PaperRcdData paper { get; set; }
- public List<RGroupList> classes { get; set; }
- public string scope { get; set; }
- }
- public record ExamRcd
- {
- public string id { get; set; }
- public string name { get; set; }
- public long startTime { get; set; }
- public long endTime { get; set; }
- public PeriodSimple period { get; set; }
- public List<Grade> grades { get; set; }
- public List<ExamSubject> subjects { get; set; }
- public List<PaperRcd> papers { get; set; }
- public List<RGroupList> classes { get; set; }
- public string scope { get; set; }
- }
- }
|