|
@@ -758,6 +758,109 @@ namespace TEAMModelOS.Controllers
|
|
|
await table.SaveOrUpdateAll(teachersUp);
|
|
|
return Ok();
|
|
|
}
|
|
|
+ [HttpPost("get-teacher-ability-files")]
|
|
|
+ public async Task<IActionResult> GetScteacher(JsonElement json) {
|
|
|
+
|
|
|
+ List<string> teachers = new List<string>();
|
|
|
+ string schoolSql = "SELECT value c.id FROM c join a in c.schools where a.areaId='870a5a6b-1ab3-461a-bdeb-baec19780ddb' and c.code='Base' ";
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
|
|
|
+ .GetItemQueryIterator<string>(schoolSql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
|
|
|
+ {
|
|
|
+ teachers.Add(item);
|
|
|
+ }
|
|
|
+ string tr =$"SELECT value(c) FROM c where c.id in ({string.Join(",", teachers.Select(x=>$"'{x}'"))}) and c.onlineTime!=0 and c.onlineTime<20 and c.pk='TeacherTrain' ";
|
|
|
+ List<TeacherTrain> teacherTrains = new List<TeacherTrain>();
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
|
|
|
+ .GetItemQueryIterator<TeacherTrain>(tr, requestOptions: new QueryRequestOptions { }))
|
|
|
+ {
|
|
|
+ if (!item.tmdid.Equals("1528783259")) {
|
|
|
+ teacherTrains.Add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ foreach (var item in teacherTrains)
|
|
|
+ {
|
|
|
+ if (item.onlineTime > 15)
|
|
|
+ {
|
|
|
+ TeacherFile teacherFile = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<TeacherFile>(item.id, new PartitionKey($"TeacherFile-{item.code.Replace("TeacherTrain-", "")}"));
|
|
|
+ foreach (var x in item.currency.teacherAilities)
|
|
|
+ {
|
|
|
+ if (x.onlineTime < 320)
|
|
|
+ {
|
|
|
+ string sql = $" select value(c) from c where c.abilityId='{x.id}' and c.code='AbilityTask-standard10'";
|
|
|
+ List<AbilityTask> abilityTasks = new List<AbilityTask>();
|
|
|
+ Dictionary<string, RecordFileAbility> valuePairs = new Dictionary<string, RecordFileAbility>();
|
|
|
+ await foreach (var y in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).GetItemQueryIterator<AbilityTask>
|
|
|
+ (sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilityTask-standard10") }))
|
|
|
+ {
|
|
|
+ abilityTasks.Add(y);
|
|
|
+ }
|
|
|
+ double limit = 0;
|
|
|
+ abilityTasks.ForEach(x =>
|
|
|
+ {
|
|
|
+ x.children.ForEach(y =>
|
|
|
+ {
|
|
|
+ y.rnodes.ForEach(r =>
|
|
|
+ {
|
|
|
+
|
|
|
+ if (valuePairs.ContainsKey(r.hash))
|
|
|
+ {
|
|
|
+ valuePairs.TryGetValue(r.hash, out var value);
|
|
|
+ value.fileAbilities.Add(new FileAbility { url = r.link, abilityId = x.abilityId, taskId = x.id, nodeId = y.id });
|
|
|
+ limit = limit + r.duration;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ valuePairs.Add(r.hash, new RecordFileAbility
|
|
|
+ {
|
|
|
+ fileRecord =
|
|
|
+ new FileRecord { hash = r.hash, size = r.size.Value, duration = r.duration, view = (int)r.duration, type = r.type, done = true },
|
|
|
+ fileAbilities = new List<FileAbility> { new FileAbility { url = r.link, abilityId = x.abilityId, taskId = x.id, nodeId = y.id } }
|
|
|
+ });
|
|
|
+ limit = limit + r.duration;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ foreach (var ps in valuePairs)
|
|
|
+ {
|
|
|
+ var fils = teacherFile.fileRecords.Find(x => x.hash.Equals(ps.Key));
|
|
|
+ if (fils != null)
|
|
|
+ {
|
|
|
+ ps.Value.fileAbilities.ForEach(x =>
|
|
|
+ {
|
|
|
+ var a = fils.files.Find(z => z.nodeId.Equals(x.nodeId) && z.abilityId.Equals(x.abilityId));
|
|
|
+ if (a == null)
|
|
|
+ {
|
|
|
+ fils.files.Add(new FileAbility { url = x.url, abilityId = x.abilityId, taskId = x.taskId, nodeId = x.nodeId });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ teacherFile.fileRecords.Add(new FileRecord
|
|
|
+ {
|
|
|
+ hash = ps.Value.fileRecord.hash,
|
|
|
+ size = ps.Value.fileRecord.size,
|
|
|
+ duration = ps.Value.fileRecord.duration,
|
|
|
+ view = (int)ps.Value.fileRecord.view,
|
|
|
+ type = ps.Value.fileRecord.type,
|
|
|
+ done = true,
|
|
|
+ files = ps.Value.fileAbilities
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ teacherFile = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync<TeacherFile>(teacherFile, teacherFile.id, new PartitionKey(teacherFile.code));
|
|
|
+ item.update.Add(StatisticsService.TeacherAbility);
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync<TeacherTrain>(item, item.id, new PartitionKey(item.code));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Ok(teacherTrains);
|
|
|
+ }
|
|
|
+
|
|
|
[HttpPost("fix-teacher-ability-files")]
|
|
|
public async Task<IActionResult> TestScteacher(JsonElement json) {
|
|
|
if (!json.TryGetProperty("ids", out JsonElement _ids)) return BadRequest();
|
|
@@ -782,92 +885,91 @@ namespace TEAMModelOS.Controllers
|
|
|
if (schools.Contains(item.code)) {
|
|
|
ids.Add(item);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
var grp = ids.GroupBy(g => g.code).Select(x => new { key = x.Key, list = x.ToList() });
|
|
|
|
|
|
- foreach (var gp in grp) {
|
|
|
- foreach (var tch in gp.list) {
|
|
|
- if (!string.IsNullOrWhiteSpace(tch.id)) {
|
|
|
- var id = ids.Find(x => x.id.Equals(tch.id))?.id;
|
|
|
- if (id != null) {
|
|
|
- TeacherFile teacherFile = new TeacherFile { id = id,pk= "TeacherFile",code= $"TeacherFile-{gp.key}",ttl=-1 };
|
|
|
- try {
|
|
|
- TeacherTrain teacherTrain = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<TeacherTrain>(id, new PartitionKey($"TeacherTrain-{gp.key}"));
|
|
|
- teacherTrain.update.Add("TeacherAbility");
|
|
|
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync<TeacherTrain>(teacherTrain,id, new PartitionKey($"TeacherTrain-{gp.key}"));
|
|
|
- } catch (Exception) {
|
|
|
- }
|
|
|
- List<AbilitySub> abilitySubs = new List<AbilitySub>();
|
|
|
- string sql = "select value(c) from c ";
|
|
|
- try {
|
|
|
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryIterator<AbilitySub>
|
|
|
- (sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilitySub-{gp.key}-{id}") }))
|
|
|
- {
|
|
|
- abilitySubs.Add(item);
|
|
|
- }
|
|
|
+ //foreach (var gp in grp) {
|
|
|
+ // foreach (var tch in gp.list) {
|
|
|
+ // if (!string.IsNullOrWhiteSpace(tch.id)) {
|
|
|
+ // var id = ids.Find(x => x.id.Equals(tch.id))?.id;
|
|
|
+ // if (id != null) {
|
|
|
+ // TeacherFile teacherFile = new TeacherFile { id = id,pk= "TeacherFile",code= $"TeacherFile-{gp.key}",ttl=-1 };
|
|
|
+ // try {
|
|
|
+ // TeacherTrain teacherTrain = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<TeacherTrain>(id, new PartitionKey($"TeacherTrain-{gp.key}"));
|
|
|
+ // teacherTrain.update.Add("TeacherAbility");
|
|
|
+ // await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync<TeacherTrain>(teacherTrain,id, new PartitionKey($"TeacherTrain-{gp.key}"));
|
|
|
+ // } catch (Exception) {
|
|
|
+ // }
|
|
|
+ // List<AbilitySub> abilitySubs = new List<AbilitySub>();
|
|
|
+ // string sql = "select value(c) from c ";
|
|
|
+ // try
|
|
|
+ // {
|
|
|
+ // await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryIterator<AbilitySub>
|
|
|
+ // (sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilitySub-{gp.key}-{id}") }))
|
|
|
+ // {
|
|
|
+ // abilitySubs.Add(item);
|
|
|
+ // }
|
|
|
|
|
|
- Dictionary<string, RecordFileAbility> valuePairs = new Dictionary<string, RecordFileAbility>();
|
|
|
- var taskids= abilitySubs.SelectMany(x => x.taskRcds).Select(x => x.id).ToHashSet();
|
|
|
- if (taskids.Any()) {
|
|
|
-
|
|
|
- List<AbilityTask> abilityTasks = new List<AbilityTask>();
|
|
|
- string taskSql = $"select distinct value(c) from c join b in c.children where c.code='AbilityTask-standard10' and b.id in ({string.Join(",", taskids.Select(m=>$"'{m}'"))})";
|
|
|
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).GetItemQueryIterator<AbilityTask>
|
|
|
- (taskSql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilityTask-standard10") }))
|
|
|
- {
|
|
|
- abilityTasks.Add(item);
|
|
|
- }
|
|
|
- abilityTasks.ForEach(x => {
|
|
|
- x.children.ForEach(y => {
|
|
|
- var di= taskids.ToList().Find(z => z.Equals(y.id));
|
|
|
- if (!string.IsNullOrWhiteSpace(id)) {
|
|
|
- y.rnodes.ForEach(r => {
|
|
|
- if (valuePairs.ContainsKey(r.hash))
|
|
|
- {
|
|
|
- valuePairs.TryGetValue(r.hash, out var value);
|
|
|
- value.fileAbilities.Add(new FileAbility { url = r.link, abilityId = x.abilityId, taskId = x.id, nodeId = r.id });
|
|
|
- }
|
|
|
- else {
|
|
|
- valuePairs.Add(r.hash, new RecordFileAbility
|
|
|
- {
|
|
|
- fileRecord =
|
|
|
- new FileRecord { hash = r.hash, size = r.size.Value, duration = r.duration, view = (int)r.duration, type = r.type, done = true },
|
|
|
- fileAbilities = new List<FileAbility> { new FileAbility { url=r.link,abilityId=x.abilityId,taskId=x.id,nodeId=r.id } }
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
- foreach (var item in valuePairs)
|
|
|
- {
|
|
|
- teacherFile.fileRecords.Add(new FileRecord
|
|
|
- {
|
|
|
- hash = item.Value.fileRecord.hash,
|
|
|
- size = item.Value.fileRecord.size,
|
|
|
- duration = item.Value.fileRecord.duration,
|
|
|
- view = (int)item.Value.fileRecord.view,
|
|
|
- type = item.Value.fileRecord.type,
|
|
|
- done = true,
|
|
|
- files = item.Value.fileAbilities
|
|
|
- });
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- return BadRequest(new { ex = ex.Message, ms = ex.StackTrace });
|
|
|
-
|
|
|
- }
|
|
|
- teacherFiles.Add(teacherFile);
|
|
|
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(teacherFile, new PartitionKey(teacherFile.code));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ // Dictionary<string, RecordFileAbility> valuePairs = new Dictionary<string, RecordFileAbility>();
|
|
|
+ // var taskids= abilitySubs.SelectMany(x => x.taskRcds).Select(x => x.id).ToHashSet();
|
|
|
+ // if (taskids.Any())
|
|
|
+ // {
|
|
|
+
|
|
|
+ // List<AbilityTask> abilityTasks = new List<AbilityTask>();
|
|
|
+ // string taskSql = $"select distinct value(c) from c join b in c.children where c.code='AbilityTask-standard10' and b.id in ({string.Join(",", taskids.Select(m=>$"'{m}'"))})";
|
|
|
+ // await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).GetItemQueryIterator<AbilityTask>
|
|
|
+ // (taskSql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilityTask-standard10") }))
|
|
|
+ // {
|
|
|
+ // abilityTasks.Add(item);
|
|
|
+ // }
|
|
|
+ // abilityTasks.ForEach(x => {
|
|
|
+ // x.children.ForEach(y => {
|
|
|
+ // var di= taskids.ToList().Find(z => z.Equals(y.id));
|
|
|
+ // if (!string.IsNullOrWhiteSpace(di)) {
|
|
|
+ // y.rnodes.ForEach(r => {
|
|
|
+ // if (valuePairs.ContainsKey(r.hash))
|
|
|
+ // {
|
|
|
+ // valuePairs.TryGetValue(r.hash, out var value);
|
|
|
+ // value.fileAbilities.Add(new FileAbility { url = r.link, abilityId = x.abilityId, taskId = x.id, nodeId = di });
|
|
|
+ // }
|
|
|
+ // else {
|
|
|
+ // valuePairs.Add(r.hash, new RecordFileAbility
|
|
|
+ // {
|
|
|
+ // fileRecord =
|
|
|
+ // new FileRecord { hash = r.hash, size = r.size.Value, duration = r.duration, view = (int)r.duration, type = r.type, done = true },
|
|
|
+ // fileAbilities = new List<FileAbility> { new FileAbility { url=r.link,abilityId=x.abilityId,taskId=x.id,nodeId=di } }
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // foreach (var item in valuePairs)
|
|
|
+ // {
|
|
|
+ // teacherFile.fileRecords.Add(new FileRecord
|
|
|
+ // {
|
|
|
+ // hash = item.Value.fileRecord.hash,
|
|
|
+ // size = item.Value.fileRecord.size,
|
|
|
+ // duration = item.Value.fileRecord.duration,
|
|
|
+ // view = (int)item.Value.fileRecord.view,
|
|
|
+ // type = item.Value.fileRecord.type,
|
|
|
+ // done = true,
|
|
|
+ // files = item.Value.fileAbilities
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // catch (Exception ex)
|
|
|
+ // {
|
|
|
+ // return BadRequest(new { ex = ex.Message, ms = ex.StackTrace });
|
|
|
+
|
|
|
+ // }
|
|
|
+ // teacherFiles.Add(teacherFile);
|
|
|
+ // await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(teacherFile, new PartitionKey(teacherFile.code));
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //}
|
|
|
|
|
|
return Ok(teacherFiles);
|
|
|
}
|