|
@@ -1,7 +1,10 @@
|
|
|
using Azure.Cosmos;
|
|
|
using DocumentFormat.OpenXml.Drawing.Charts;
|
|
|
using DocumentFormat.OpenXml.Office2010.Excel;
|
|
|
+using HTEXLib.Helpers.ShapeHelpers;
|
|
|
using MathNet.Numerics.Distributions;
|
|
|
+using Microsoft.AspNetCore.Http;
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
@@ -222,6 +225,116 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ public static async Task<(List<ExamInfo> datas, string continuationToken)> FindExam(JsonElement request, string id, string school, AzureCosmosFactory _azureCosmos)
|
|
|
+ {
|
|
|
+ List<ExamInfo> examInfo = new();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ string sub = string.Empty;
|
|
|
+ string subject = string.Empty;
|
|
|
+ /* if (request.TryGetProperty("subjectId", out JsonElement subjectId) && !string.IsNullOrWhiteSpace($"{subjectId}"))
|
|
|
+ {
|
|
|
+ sub = $" join A0 in c.subjects ";
|
|
|
+ subject = $" and A0.id = '{subjectId}'";
|
|
|
+ }*/
|
|
|
+ StringBuilder stringBuilder = new($"select c.id,c.name,c.code,c.period,c.startTime,c.endTime,c.stuCount,c.type,c.progress,c.examType,c.createTime,c.source, c.subjects, c.grades,c.owner, c.scope,c.classes, c.stuLists, c.sRate,c.lostStu,c.sStatus,c.qamode,c.school,c.cloudas from c where (c.status<>404 or IS_DEFINED(c.status) = false) and c.pk = 'Exam'");
|
|
|
+ //开始时间,
|
|
|
+ if (request.TryGetProperty("stime", out JsonElement stime))
|
|
|
+ {
|
|
|
+ if (long.TryParse($"{stime}", out long data))
|
|
|
+ {
|
|
|
+ stringBuilder.Append($" and c.startTime >= {data} ");
|
|
|
+
|
|
|
+ };
|
|
|
+ };
|
|
|
+ //默认当前时间
|
|
|
+ var etimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
+ stringBuilder.Append($" and c.startTime <= {etimestamp} ");
|
|
|
+ /*if (request.TryGetProperty("etime", out JsonElement etime))
|
|
|
+ {
|
|
|
+ if (long.TryParse($"{etime}", out long data))
|
|
|
+ {
|
|
|
+ stringBuilder.Append($" and c.createTime <= {data} ");
|
|
|
+ };
|
|
|
+ };*/
|
|
|
+ string periodId = string.Empty;
|
|
|
+
|
|
|
+ if (request.TryGetProperty("name", out JsonElement name) && !string.IsNullOrWhiteSpace($"{name}"))
|
|
|
+ {
|
|
|
+ stringBuilder.Append($" and Contains( c.name , '{name}') = true ");
|
|
|
+ }
|
|
|
+ if (request.TryGetProperty("owner", out JsonElement owner) && !string.IsNullOrWhiteSpace($"{owner}"))
|
|
|
+ {
|
|
|
+ stringBuilder.Append($" and c.owner = '{owner}' ");
|
|
|
+ }
|
|
|
+ if (request.TryGetProperty("source", out JsonElement source) && !string.IsNullOrWhiteSpace($"{source}"))
|
|
|
+ {
|
|
|
+ stringBuilder.Append($" and c.source = '{source}' ");
|
|
|
+ }
|
|
|
+ if (request.TryGetProperty("type", out JsonElement type))
|
|
|
+ {
|
|
|
+
|
|
|
+ if (!type.ValueKind.Equals(JsonValueKind.Undefined) && !type.ValueKind.Equals(JsonValueKind.Null) && type.ValueKind.Equals(JsonValueKind.String))
|
|
|
+ {
|
|
|
+ stringBuilder.Append($" and c.pk = '{type}' ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ stringBuilder.Append("order by c.createTime desc");
|
|
|
+ //string token = null;
|
|
|
+ string token = default;
|
|
|
+ //默认不指定返回大小
|
|
|
+ int? topcout = null;
|
|
|
+ if (request.TryGetProperty("count", out JsonElement jcount))
|
|
|
+ {
|
|
|
+ if (!jcount.ValueKind.Equals(JsonValueKind.Undefined) && !jcount.ValueKind.Equals(JsonValueKind.Null) && jcount.TryGetInt32(out int data))
|
|
|
+ {
|
|
|
+ topcout = data;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //是否需要进行分页查询,默认不分页
|
|
|
+ bool iscontinuation = false;
|
|
|
+ if (topcout != null && topcout.Value > 0)
|
|
|
+ {
|
|
|
+ iscontinuation = true;
|
|
|
+ }
|
|
|
+ //如果指定了返回大小
|
|
|
+ if (request.TryGetProperty("continuationToken", out JsonElement token_1))
|
|
|
+ {
|
|
|
+ if (!token_1.ValueKind.Equals(JsonValueKind.Null) && token_1.ValueKind.Equals(JsonValueKind.String))
|
|
|
+ {
|
|
|
+ token = token_1.GetString();
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIterator(queryText: stringBuilder.ToString(), continuationToken: token, requestOptions: new QueryRequestOptions() { MaxItemCount = topcout }))
|
|
|
+ {
|
|
|
+
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ examInfo.Add(obj.ToObject<ExamInfo>());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iscontinuation)
|
|
|
+ {
|
|
|
+ token = item.GetContinuationToken();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return (examInfo, token);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ return (examInfo,"500");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
/*
|
|
|
public static async Task<string> getKnowledges(List<string> knowledges,List<ExamClassResult> answers ,string sub,List<List<string>> kones,List<double> point) {
|
|
|
foreach (string k in knowledges)
|