|
@@ -47,7 +47,7 @@ namespace TEAMModelOS.Controllers
|
|
|
private readonly NotificationService _notificationService;
|
|
|
|
|
|
public ExamController(AzureCosmosFactory azureCosmos, AzureServiceBusFactory serviceBus, SnowflakeId snowflakeId, DingDing dingDing,
|
|
|
- IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, NotificationService notificationService,IConfiguration configuration)
|
|
|
+ IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, NotificationService notificationService, IConfiguration configuration)
|
|
|
{
|
|
|
_azureCosmos = azureCosmos;
|
|
|
_serviceBus = serviceBus;
|
|
@@ -86,24 +86,30 @@ namespace TEAMModelOS.Controllers
|
|
|
request.startTime = now;
|
|
|
}
|
|
|
//查询所有学生名单
|
|
|
- /* List<string> sids = new List<string>();
|
|
|
- //List<Student> students = new List<Student>();
|
|
|
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: $"select c.id from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{request.school}") }))
|
|
|
- {
|
|
|
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
- {
|
|
|
- var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
|
|
|
- while (accounts.MoveNext())
|
|
|
- {
|
|
|
- JsonElement account = accounts.Current;
|
|
|
- sids.Add(account.GetProperty("id").GetString());
|
|
|
- }
|
|
|
- }
|
|
|
- }*/
|
|
|
+ /* List<string> sids = new List<string>();
|
|
|
+ //List<Student> students = new List<Student>();
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: $"select c.id from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{request.school}") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
|
|
|
+ while (accounts.MoveNext())
|
|
|
+ {
|
|
|
+ JsonElement account = accounts.Current;
|
|
|
+ sids.Add(account.GetProperty("id").GetString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }*/
|
|
|
//int stuCount = 0;
|
|
|
+ List<(string pId, List<string> gid)> ps = new();
|
|
|
+ foreach (var gp in request.groupLists) {
|
|
|
+ ps.Add((gp.Key, gp.Value));
|
|
|
+ }
|
|
|
List<string> classes = ExamService.getClasses(request.classes, request.stuLists);
|
|
|
- (List<RMember> tchList, List<RGroupList> classLists) = await GroupListService.GetStutmdidListids(client, _dingDing, classes, request.school);
|
|
|
+ (List<RMember> tchList, List<RGroupList> classLists) = await GroupListService.GetStutmdidListids(client, _dingDing, classes, request.school, ps);
|
|
|
+ request.stuCount = tchList.Count;
|
|
|
+
|
|
|
/*for (int i = 0; i < classes.Count; i++)
|
|
|
{
|
|
|
List<string> ids = new List<string>();
|
|
@@ -144,7 +150,7 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
stuCount += ids.Count;
|
|
|
}*/
|
|
|
- request.stuCount = tchList.Count;
|
|
|
+
|
|
|
if (string.IsNullOrEmpty(request.id))
|
|
|
{
|
|
|
request.id = Guid.NewGuid().ToString();
|
|
@@ -568,7 +574,7 @@ namespace TEAMModelOS.Controllers
|
|
|
//确定当前学生所在班级且该班级参与该活动
|
|
|
List<string> cIds = new();
|
|
|
if (ids.Count == 0) return Ok(new { code = 1, msg = "未找到相关班级信息" });
|
|
|
- if(string.IsNullOrEmpty(userId)) return Ok(new { code = 1, msg = "当前用户信息未找到" });
|
|
|
+ if (string.IsNullOrEmpty(userId)) return Ok(new { code = 1, msg = "当前用户信息未找到" });
|
|
|
foreach (string cId in ids)
|
|
|
{
|
|
|
//List<string> stus = new List<string>();
|
|
@@ -1217,7 +1223,7 @@ namespace TEAMModelOS.Controllers
|
|
|
requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"GroupList") }))
|
|
|
{
|
|
|
stuLists.Add(item);
|
|
|
- }
|
|
|
+ }
|
|
|
await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<GroupList>(queryText: $"select c.id from c join A0 in c.students where A0.id = '{studentId}'",
|
|
|
requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"GroupList-{school}") }))
|
|
|
{
|
|
@@ -1745,7 +1751,7 @@ namespace TEAMModelOS.Controllers
|
|
|
}*/
|
|
|
|
|
|
[ProducesDefaultResponseType]
|
|
|
- //[AuthToken(Roles = "Student")]
|
|
|
+ [AuthToken(Roles = "teacher,admin")]
|
|
|
[HttpPost("scoring")]
|
|
|
public async Task<IActionResult> scoring(JsonElement requert)
|
|
|
{
|
|
@@ -1759,8 +1765,8 @@ namespace TEAMModelOS.Controllers
|
|
|
//if (!requert.TryGetProperty("type", out JsonElement type)) return BadRequest();
|
|
|
if (!requert.TryGetProperty("tmdId", out JsonElement tId)) return BadRequest();
|
|
|
if (!requert.TryGetProperty("count", out JsonElement scount)) return BadRequest();
|
|
|
-
|
|
|
- var client = _azureCosmos.GetCosmosClient();
|
|
|
+
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
//var redisClient = _azureRedis.GetRedisClient(8);
|
|
|
ExamInfo info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"Exam-{code}"));
|
|
|
List<ExamClassResult> classResults = new();
|
|
@@ -1833,7 +1839,8 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if (attr.Count > 0) {
|
|
|
+ if (attr.Count > 0)
|
|
|
+ {
|
|
|
foreach (SDK.Models.Cosmos.Common.Scoring ss in attr)
|
|
|
{
|
|
|
|
|
@@ -1865,18 +1872,21 @@ namespace TEAMModelOS.Controllers
|
|
|
var obj = new { ss.id, ss.stuId, ss.examId, ss.subjectId, item = sc, ss.qs, blob = ansBlob, ss.tIds, scores = scores, ss.model, ss.mode };
|
|
|
objs.Add(obj);
|
|
|
}
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
if (requert.TryGetProperty("stuId", out JsonElement stuId))
|
|
|
{
|
|
|
objs = await Review(attrSc, id.GetString(), code.GetString(), subjectId.GetString(), scount.GetInt32(), tId.GetString(), stuId.GetString());
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
objs = await Review(attrSc, id.GetString(), code.GetString(), subjectId.GetString(), scount.GetInt32(), tId.GetString(), "");
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
var fp = attr.Count > 0 ? Math.Round(finishCount * 1.0 / (attrSc.Count * correct.num), 2) : 0;
|
|
|
return Ok(new { objs, paper = info.papers[index].blob, fp });
|
|
|
}
|
|
@@ -1984,7 +1994,7 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
attr.Add(item);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
int index = 0;
|
|
|
foreach (ExamSubject subject in info.subjects)
|
|
|
{
|
|
@@ -2029,7 +2039,7 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
|
|
|
//批阅,给老师随机分配阅卷数据,以及查询改老师已有的阅卷数据
|
|
|
- private async Task<List<dynamic>> Review(List<SDK.Models.Cosmos.Common.Scoring> attr, string id,string code,string subjectId,int count,string tId,string stuId)
|
|
|
+ private async Task<List<dynamic>> Review(List<SDK.Models.Cosmos.Common.Scoring> attr, string id, string code, string subjectId, int count, string tId, string stuId)
|
|
|
{
|
|
|
//ResponseBuilder builder = ResponseBuilder.custom();
|
|
|
//var (id, school) = HttpContext.GetAuthTokenInfo();
|
|
@@ -2090,12 +2100,13 @@ namespace TEAMModelOS.Controllers
|
|
|
//var scc = ss.items.SelectMany(p => p.scores, (p, d) => new { p.ssc, d.sc, d.tmdId }).Where(x => x.tmdId.Equals(tId.GetString())).Select(m => new { m.sc, m.ssc });
|
|
|
List<dynamic> sc = new List<dynamic>();
|
|
|
int indexScore = 0;
|
|
|
+ ss.qs = ss.qs.Where(s => !string.IsNullOrEmpty(s.tId)).ToList();
|
|
|
(string ansBlob, List<double> scores) = await getMoreStuInfo(client, ss.stuId, ss.examId, ss.subjectId, code);
|
|
|
foreach (Item item in ss.items)
|
|
|
{
|
|
|
List<double> scc = item.scores.Where(x => x.tmdId.Equals(tId)).Select(c => c.sc).ToList();
|
|
|
//item.scores.Where(x => x.tmdId.Equals(tId.GetString())).SelectMany(p => p.sc, (p, d) => new { });
|
|
|
-
|
|
|
+
|
|
|
if (scc.Count > 0)
|
|
|
{
|
|
|
sc.Add(new { sc = scc.FirstOrDefault(), item.ssc });
|
|
@@ -2117,7 +2128,8 @@ namespace TEAMModelOS.Controllers
|
|
|
List<SDK.Models.Cosmos.Common.Scoring> notYet = new();
|
|
|
notYet = all.Where(x => x.tIds.Count < x.count * x.model - 1).ToList();
|
|
|
List<dynamic> objs = new List<dynamic>();
|
|
|
- for (int i = 0;i< count; i++) {
|
|
|
+ for (int i = 0; i < count; i++)
|
|
|
+ {
|
|
|
Random random = new Random();
|
|
|
SDK.Models.Cosmos.Common.Scoring item = new();
|
|
|
if (notYet.Count > 0)
|
|
@@ -2141,6 +2153,7 @@ namespace TEAMModelOS.Controllers
|
|
|
List<dynamic> sc = new List<dynamic>();
|
|
|
(string ansBlob, List<double> scores) = await getMoreStuInfo(client, item.stuId, item.examId, item.subjectId, code);
|
|
|
int indexScore = 0;
|
|
|
+ item.qs = item.qs.Where(s => !string.IsNullOrEmpty(s.tId)).ToList();
|
|
|
foreach (Item its in item.items)
|
|
|
{
|
|
|
List<double> ssc = its.scores.Where(x => x.tmdId.Equals(tId)).Select(c => c.sc).ToList();
|
|
@@ -2209,12 +2222,12 @@ namespace TEAMModelOS.Controllers
|
|
|
return Ok(obj);
|
|
|
}*/
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
await _dingDing.SendBotMsg($"OS,{_option.Location},exam/review\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
- return new List<dynamic>() { new { code = 404,msg = "分配任务异常"} };
|
|
|
+ return new List<dynamic>() { new { code = 404, msg = "分配任务异常" } };
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -2309,14 +2322,15 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if (ssc[itemIndex] >= 0) {
|
|
|
+ if (ssc[itemIndex] >= 0)
|
|
|
+ {
|
|
|
Info info = new();
|
|
|
info.sc = ssc[itemIndex];
|
|
|
info.tmdId = tId.GetString();
|
|
|
info.mark = marks.Count > 0 ? marks[itemIndex] : "";
|
|
|
info.index = itemIndex;
|
|
|
item.scores.Add(info);
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
itemIndex++;
|
|
|
}
|
|
@@ -2346,26 +2360,31 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
bool isFinish = false;
|
|
|
int scount = attr.Select(a => a.items[0].scores).ToList().Count;
|
|
|
- foreach (SDK.Models.Cosmos.Common.Scoring sc in attr) {
|
|
|
- foreach (var item in sc.items) {
|
|
|
+ foreach (SDK.Models.Cosmos.Common.Scoring sc in attr)
|
|
|
+ {
|
|
|
+ foreach (var item in sc.items)
|
|
|
+ {
|
|
|
if (item.scores.Count == 0)
|
|
|
{
|
|
|
isFinish = false;
|
|
|
break;
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
if (item.scores.Count != correct.num)
|
|
|
{
|
|
|
isFinish = false;
|
|
|
break;
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
isFinish = true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if (isFinish) {
|
|
|
+ if (isFinish)
|
|
|
+ {
|
|
|
foreach (ExamClassResult exam in classResults)
|
|
|
{
|
|
|
foreach (SDK.Models.Cosmos.Common.Scoring scoring in attr)
|
|
@@ -2379,7 +2398,7 @@ namespace TEAMModelOS.Controllers
|
|
|
var ace = item.scores.Where(x => string.IsNullOrEmpty(x.tmdId)).ToList();
|
|
|
if (ace.Count > 0)
|
|
|
{
|
|
|
- return Ok(new { code = 1 ,msg = "用户信息未找到"});
|
|
|
+ return Ok(new { code = 1, msg = "用户信息未找到" });
|
|
|
}
|
|
|
//判定是否仲裁卷
|
|
|
if (!item.flag)
|
|
@@ -2399,7 +2418,7 @@ namespace TEAMModelOS.Controllers
|
|
|
from = $"ies5:{_option.Location}:private",
|
|
|
to = ids,
|
|
|
label = $"{bizcode}_school",
|
|
|
- body = new { location = _option.Location, biz = bizcode, tmdid = userid, tmdname = name.ToString(), schoolcode = school, schoolname = $"{schname}",examname = correct.name, status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
|
|
|
+ body = new { location = _option.Location, biz = bizcode, tmdid = userid, tmdname = name.ToString(), schoolcode = school, schoolname = $"{schname}", examname = correct.name, status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
|
|
|
expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
|
|
|
};
|
|
|
var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
|
|
@@ -2408,12 +2427,13 @@ namespace TEAMModelOS.Controllers
|
|
|
var location = _option.Location;
|
|
|
await _notificationService.SendNotification(clientID, clientSecret, location, url, notification);
|
|
|
await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(scoring, scoring.id, new PartitionKey(scoring.code));
|
|
|
- return Ok(new { msg = "需要仲裁" ,code = 2});
|
|
|
+ return Ok(new { msg = "需要仲裁", code = 2 });
|
|
|
}
|
|
|
- if (item.scores.Count > 0) {
|
|
|
+ if (item.scores.Count > 0)
|
|
|
+ {
|
|
|
double sc = item.scores.Select(x => x.sc).ToList().Aggregate((i, j) => (i + j) / item.scores.Count);
|
|
|
scoring.scores[itemIndex] = sc;
|
|
|
- }
|
|
|
+ }
|
|
|
string tmdId = tId.GetString();
|
|
|
//定位老师是几阅
|
|
|
int indexOfSc = 0;
|
|
@@ -2460,7 +2480,7 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(exam, exam.id, new PartitionKey($"{exam.code}"));
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
return Ok(new { code = 200 });
|
|
|
}
|
|
|
catch (Exception ex)
|
|
@@ -2517,7 +2537,7 @@ namespace TEAMModelOS.Controllers
|
|
|
schname = jsonschname.ToString();
|
|
|
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
SDK.Models.Cosmos.Common.Scoring scoring = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<SDK.Models.Cosmos.Common.Scoring>(id.GetString(), new PartitionKey($"Scoring-{code}"));
|
|
|
if (null != scoring)
|
|
|
{
|
|
@@ -2552,7 +2572,7 @@ namespace TEAMModelOS.Controllers
|
|
|
from = $"ies5:{_option.Location}:private",
|
|
|
to = ids,
|
|
|
label = $"{bizcode}_school",
|
|
|
- body = new { location = _option.Location, biz = bizcode, tmdid = userid, tmdname = name.ToString(), schoolcode = school, schoolname = $"{schname}",examname = correct.name, status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
|
|
|
+ body = new { location = _option.Location, biz = bizcode, tmdid = userid, tmdname = name.ToString(), schoolcode = school, schoolname = $"{schname}", examname = correct.name, status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
|
|
|
expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
|
|
|
};
|
|
|
var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
|
|
@@ -2882,7 +2902,8 @@ namespace TEAMModelOS.Controllers
|
|
|
await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemsStreamAsync(correctIds, $"CorrectTask-{tId}");
|
|
|
}
|
|
|
}*/
|
|
|
- private async Task<(string blob,List<double>)> getMoreStuInfo(CosmosClient client, string stuId, string examId,string subjectId,string code) {
|
|
|
+ private async Task<(string blob, List<double>)> getMoreStuInfo(CosmosClient client, string stuId, string examId, string subjectId, string code)
|
|
|
+ {
|
|
|
var queryClass = $"select c.studentAnswers,c.studentIds,c.studentScores from c where array_contains(c.studentIds,'{stuId}') and c.examId = '{examId}' and c.subjectId = '{subjectId}'";
|
|
|
List<List<string>> ans = new List<List<string>>();
|
|
|
List<string> ids = new List<string>();
|