|
@@ -272,6 +272,160 @@ namespace TEAMModelOS.Controllers
|
|
|
return Ok(new { error = 400 });
|
|
|
}
|
|
|
}
|
|
|
+ private async IAsyncEnumerable<List<AbilitySub>> GetSubsAsyn(List<string> tmdids, string _school, HashSet<string> ids)
|
|
|
+ {
|
|
|
+
|
|
|
+ foreach (var tmdid in tmdids)
|
|
|
+ {
|
|
|
+ List<AbilitySub> abilitySubs = new List<AbilitySub>();
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher")
|
|
|
+ .GetItemQueryIterator<AbilitySub>(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AbilitySub-{_school}-{tmdid}") }))
|
|
|
+ {
|
|
|
+ ids.Add(item.id);
|
|
|
+ abilitySubs.Add(item);
|
|
|
+ }
|
|
|
+ yield return abilitySubs;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 批量更新认证材料分数。
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("score-teacher-submit")]
|
|
|
+ [AuthToken(Roles = "admin,teacher", Permissions = "train-appraise")]
|
|
|
+ public async Task<IActionResult> UpsertSubmitScore(JsonElement request)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (!HttpContext.Items.TryGetValue("Standard", out object standard)) return BadRequest();
|
|
|
+ if (!request.TryGetProperty("score", out JsonElement _score)) return BadRequest();
|
|
|
+ if (!request.TryGetProperty("tmdids", out JsonElement _tmdids)) return BadRequest();
|
|
|
+ if (!request.TryGetProperty("roleType", out JsonElement _roleType)) return BadRequest();
|
|
|
+ var (userid, name, picture, school) = HttpContext.GetAuthTokenInfo();
|
|
|
+ int score = -999;
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ int.TryParse($"{_score}", out score);
|
|
|
+ List<string> tmdids = _tmdids.ToObject<List<string>>();
|
|
|
+ List<AbilitySub> abilitySubs = new List<AbilitySub>();
|
|
|
+ HashSet<AbilitySub> subs = new HashSet<AbilitySub>();
|
|
|
+ HashSet<string> ids = new HashSet<string>();
|
|
|
+ // List<string> abilities = new List<string>();
|
|
|
+ await foreach (var item in GetSubsAsyn(tmdids, school, ids))
|
|
|
+ {
|
|
|
+
|
|
|
+ abilitySubs.AddRange(item);
|
|
|
+ }
|
|
|
+ var su = abilitySubs.FindAll(x => x.from == 1);
|
|
|
+ if (su.IsNotEmpty())
|
|
|
+ {
|
|
|
+ subs = new HashSet<AbilitySub>(su);
|
|
|
+ }
|
|
|
+ if (ids.Count > 0)
|
|
|
+ {
|
|
|
+ string queryText = $"SELECT value(c.id) FROM c WHERE c.currency=1 and c.id IN ({string.Join(",", ids.Select(o => $"'{o}'"))})";
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Normal")
|
|
|
+ .GetItemQueryIterator<string>(queryText: queryText, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Ability-{standard}") }))
|
|
|
+ {
|
|
|
+ var sb = abilitySubs.Find(x => x.id.Equals(item));
|
|
|
+ if (sb != null)
|
|
|
+ {
|
|
|
+ subs.Add(sb);
|
|
|
+ }
|
|
|
+ //abilities.Add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (subs.Count > 0 && score >= -1 && score <= 1)
|
|
|
+ {
|
|
|
+ long nowTime = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
|
|
+ List<Task<ItemResponse<AbilitySub>>> abilitySubTasks = new List<Task<ItemResponse<AbilitySub>>>();
|
|
|
+ subs.ToList().ForEach(sub => {
|
|
|
+ OtherScore otherScore = null;
|
|
|
+ if ($"{_roleType}".Equals("school") || $"{_roleType}".Equals("school") || $"{_roleType}".Equals("school"))
|
|
|
+ {
|
|
|
+ otherScore = sub.otherScore.Find(x => x.roleType.Equals($"{_roleType}"));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ otherScore = sub.otherScore.Find(x => x.roleType.Equals($"{_roleType}") && x.tmdid.Equals(userid));
|
|
|
+ }
|
|
|
+ if (otherScore != null)
|
|
|
+ {
|
|
|
+ otherScore.score = score;
|
|
|
+ otherScore.scoreUploads.ForEach(x => {
|
|
|
+ x.score = score;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (sub.uploads != null)
|
|
|
+ {
|
|
|
+ List<ScoreUpload> scoreUploads = new List<ScoreUpload>();
|
|
|
+ sub.uploads.ForEach(x => {
|
|
|
+ scoreUploads.Add(new ScoreUpload
|
|
|
+ {
|
|
|
+ score = score,
|
|
|
+ stdid = x.stdid,
|
|
|
+ taskid = x.taskid,
|
|
|
+ titleIds = x.titleIds,
|
|
|
+ });
|
|
|
+ });
|
|
|
+ otherScore = new OtherScore
|
|
|
+ {
|
|
|
+ roleType = $"{_roleType}",
|
|
|
+ tmdid = userid,
|
|
|
+ tmdname = name,
|
|
|
+ score = score,
|
|
|
+ time = nowTime,
|
|
|
+ scoreUploads = scoreUploads
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ abilitySubTasks.Add(client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(sub, sub.id, new PartitionKey(sub.code)));
|
|
|
+ });
|
|
|
+ List<Task> tasks = new List<Task>();
|
|
|
+ tmdids.ForEach(x => {
|
|
|
+ tasks.Add(StatisticsService.SendServiceBus($"{standard}", $"{x}", $"{school}", StatisticsService.TeacherAility, 1, _configuration, _serviceBus));
|
|
|
+ });
|
|
|
+ int pagesize = 50;
|
|
|
+ if (abilitySubTasks.Count <= pagesize)
|
|
|
+ {
|
|
|
+ await Task.WhenAll(abilitySubTasks);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ int pages = (abilitySubTasks.Count + pagesize) / pagesize; //256是批量操作最大值,pages = (total + max -1) / max;
|
|
|
+ for (int i = 0; i < pages; i++)
|
|
|
+ {
|
|
|
+ var lists = abilitySubTasks.Skip((i) * pagesize).Take(pagesize).ToList();
|
|
|
+ await Task.WhenAll(lists);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (tasks.Count <= pagesize)
|
|
|
+ {
|
|
|
+ await Task.WhenAll(tasks);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ int pages = (tasks.Count + pagesize) / pagesize; //256是批量操作最大值,pages = (total + max -1) / max;
|
|
|
+ for (int i = 0; i < pages; i++)
|
|
|
+ {
|
|
|
+ var listssb = tasks.Skip((i) * pagesize).Take(pagesize).ToList();
|
|
|
+ await Task.WhenAll(listssb);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Ok(new { status = 200 });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"OS,{_option.Location},UpsertSubmitScore/UpsertSubmitScore()\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ }
|
|
|
+ return Ok(new { error = 0, msg = "参数异常" });
|
|
|
+ }
|
|
|
/// <summary>
|
|
|
/// 对某个订阅的能力点进行操作
|
|
|
/// </summary>
|