123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314 |
-
- using Microsoft.Azure.Cosmos;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Options;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.Json;
- using System.Threading.Tasks;
- using TEAMModelOS.Models;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK;
- using TEAMModelOS.SDK.Models;
- using TEAMModelOS.SDK.Extension;
- using static TEAMModelOS.Controllers.SchoolTeacherController;
-
- using TEAMModelOS.Filter;
- using Azure;
- using Azure.Messaging.ServiceBus;
- using Microsoft.Extensions.Configuration;
- using Microsoft.AspNetCore.Authorization;
- using System.Net.Http;
- namespace TEAMModelOS.Controllers
- {
- [ProducesResponseType(StatusCodes.Status200OK)]
- [ProducesResponseType(StatusCodes.Status400BadRequest)]
-
- [Route("research/ability")]
- [ApiController]
- public class AbilitySubController : ControllerBase
- {
- private readonly AzureCosmosFactory _azureCosmos;
- private readonly SnowflakeId _snowflakeId;
- private readonly DingDing _dingDing;
- private readonly Option _option;
- private readonly HttpTrigger _httpTrigger;
- private readonly AzureServiceBusFactory _serviceBus;
- private readonly AzureStorageFactory _azureStorage;
- private readonly CoreAPIHttpService _coreAPIHttpService;
- private readonly IHttpClientFactory _httpClient;
- public IConfiguration _configuration { get; set; }
- public AbilitySubController(IHttpClientFactory httpClientFactory, CoreAPIHttpService coreAPIHttpService, AzureStorageFactory azureStorage,AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option, HttpTrigger httpTrigge, AzureServiceBusFactory serviceBus, IConfiguration configuration)
- {
- _azureCosmos = azureCosmos;
- _snowflakeId = snowflakeId;
- _dingDing = dingDing;
- _option = option?.Value;
- _httpTrigger = httpTrigge;
- _serviceBus = serviceBus;
- _configuration = configuration;
- _azureStorage = azureStorage;
- _coreAPIHttpService = coreAPIHttpService;
- _httpClient = httpClientFactory;
- }
-
- /// <summary>
- /// 保存
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("save-subs")]
- [Authorize(Roles = "IES")]
- [AuthToken(Roles = "teacher,admin,area")]
- public async Task<IActionResult> SaveSubs(JsonElement request)
- {
- try
- {
- (string id, _, _, string school) = HttpContext.GetAuthTokenInfo();
- if (string.IsNullOrEmpty(school))
- {
- if (!request.TryGetProperty("school", out JsonElement _school))
- {
- return BadRequest();
- }
- else
- {
- school = $"{_school}";
- }
- }
- var client = _azureCosmos.GetCosmosClient();
- if (!request.TryGetProperty("tmdid", out JsonElement _tmdid)) return BadRequest();
- if (!request.TryGetProperty("abilityIds", out JsonElement _abilityIds)) return BadRequest();
- List<string> abilityIds = _abilityIds.ToObject<List<string>>();
- foreach (var abilityId in abilityIds)
- {
- if (!string.IsNullOrEmpty(abilityId))
- {
- string code = $"AbilitySub-{school}-{_tmdid}";
- try
- {
- await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<AbilitySub>(abilityId, new PartitionKey(code));
- }
- catch (CosmosException ex)
- {
- if (ex.Status == 404)
- {
- AbilitySub abilitySub = new AbilitySub
- {
- id = abilityId,
- code = $"AbilitySub-{school}-{_tmdid}",
- school = $"{school}",
- creatorId = $"{_tmdid}",
- done = false,
- hour = 0,
- comid = Guid.NewGuid().ToString(),
- pk = "AbilitySub"
- };
- await client.GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(abilitySub, new PartitionKey(abilitySub.code));
- }
- }
- }
- }
- if (!HttpContext.Items.TryGetValue("Standard", out object standard)) return BadRequest();
- await StatisticsService.SendServiceBus( ($"{standard}", new List<string> { $"{_tmdid}" }, $"{school}",new List<string> { StatisticsService.TeacherAbility }, 0), _configuration, _serviceBus, client);
- return Ok(new { abilityIds });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},AbilityController/SaveSubs()\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
- return BadRequest();
- }
- }
- /// <summary>
- ///当前老师 获取没有订阅以及已经订阅的能力点学习课程
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [AuthToken(Roles = "teacher,admin,area")]
- [HttpPost("get-subs")]
- [Authorize(Roles = "IES")]
- public async Task<IActionResult> GetSubs(JsonElement request)
- {
- try
- {
- var client = _azureCosmos.GetCosmosClient();
- if (!HttpContext.Items.TryGetValue("Standard", out object standard)) return Ok(new { error = 400 });
- ///没有订阅的
- List<Ability> notSub = new List<Ability>();
- ///已经订阅的
- List<Ability> hadSubs = new List<Ability>();
- ///订阅的学习记录
- List<AbilitySub> rcdSubs = new List<AbilitySub>();
- //必修
- List<Ability> currencyAb1 = new List<Ability>();
- //通识
- List<Ability> currencyAb2 = new List<Ability>();
- //tmdid
- if (!request.TryGetProperty("tmdid", out JsonElement tmdid)) return Ok(new { error = 400 });
- //学校编码
- (string id, _, _, string school) = HttpContext.GetAuthTokenInfo();
- if (string.IsNullOrEmpty(school))
- {
- if (!request.TryGetProperty("school", out JsonElement _school))
- {
- return Ok(new { error = 400 });
- }
- else
- {
- school = $"{_school}";
- }
- }
- if (!string.IsNullOrEmpty(school))
- {
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Normal")
- .GetItemQueryIteratorSql<Ability>(queryText: $"select value(c) from c where c.status = 1 ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Ability-{standard}") }))
- {
- notSub.Add(item);
- if (item.currency == 2)
- {
- currencyAb2.Add(item);
- }
- if (item.currency == 1)
- {
- currencyAb1.Add(item);
- }
- }
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher")
- .GetItemQueryIteratorSql<AbilitySub>(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AbilitySub-{school}-{tmdid}") }))
- {
- var had = notSub.Where(x => x.id.Equals(item.id)).FirstOrDefault();
- if (had != null)
- {
- notSub.Remove(had);
- hadSubs.Add(had);
- }
- rcdSubs.Add(item);
- }
- }
- else
- {
- return Ok(new { error = 400 });
- };
- (string accessConfig, Area area, AreaSetting setting) = await ThirdService.GetAccessConfig(client, $"{standard}");
- //automatic,自动分配系统设置的=0,manual手动挑选的=1
- int from = 0;
- //未对接其他平台。有对接其他平台则必修。
- if (!string.IsNullOrEmpty(accessConfig))
- {
- Teacher teacher = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Teacher>(id, new PartitionKey("Base"));
-
-
- var abilitys = await ThirdService.GetDiagnosisList(client, $"{standard}", _dingDing, setting, _httpClient.CreateClient(), teacher, _option,_azureStorage);
- if (abilitys != null)
- {
- abilitys.ForEach(x => { x.currency = 1; });
- currencyAb1 = abilitys;
- //同时处理 原有设置必修的能力点。
- hadSubs.FindAll(x => abilitys.Exists(z=>z.id.Equals(x.id))).ForEach(y => { y.currency = 1; });
- from = 1;
- }
- else
- {
- currencyAb1 = null;
- }
- }
- //通识
- foreach (var item in currencyAb2)
- {
- var had = hadSubs.Where(x => x.id.Equals(item.id)).FirstOrDefault();
- if (had == null)
- {
- item.currency = 2;
- hadSubs.Add(item);
- AbilitySub abilitySub = new AbilitySub
- {
- id = item.id,
- code = $"AbilitySub-{school}-{id}",
- school = $"{school}",
- creatorId = $"{id}",
- done = false,
- hour = 0,
- comid = Guid.NewGuid().ToString(),
- pk = "AbilitySub" ,
- from = 0,
- currency = item.currency
- };
- try
- {
- await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(abilitySub, new PartitionKey(abilitySub.code));
- }
- catch (CosmosException ex) when (ex.Status == 409)
- {
- continue;
- }
- catch (Exception ex) {
- await _dingDing.SendBotMsg($"OS,{_option.Location},AbilityController:get-subs\n{ex.Message}\n{ex.StackTrace}\n\n{request.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
- continue;
- }
- }
- }
- if (currencyAb1 != null)
- {
- //必修
- foreach (var item in currencyAb1)
- {
- var had = hadSubs.Where(x => x.id.Equals(item.id)).FirstOrDefault();
- if (had == null)
- {
- item.currency = 1;
- hadSubs.Add(item);
- AbilitySub abilitySub = new AbilitySub
- {
- id = item.id,
- code = $"AbilitySub-{school}-{id}",
- school = $"{school}",
- creatorId = $"{id}",
- done = false,
- hour = 0,
- comid = Guid.NewGuid().ToString(),
- pk = "AbilitySub",
- from=from,
- currency = item.currency
- };
- try
- {
- await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(abilitySub, new PartitionKey(abilitySub.code));
- }
- catch (CosmosException ex) when (ex.Status == 409) {
- continue;
- }
- }
- }
- }
- return Ok(new { rcdSubs, hadSubs });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},AbilityController:get-subs\n{ex.Message}\n{ex.StackTrace}\n{request.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
- 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")
- .GetItemQueryIteratorSql<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")]
- [Authorize(Roles = "IES")]
- [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")
- .GetItemQueryIteratorSql<string>(queryText: queryText, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Ability-{standard}") }))
- {
- var sb = abilitySubs.FindAll(x => x.id.Equals(item));
- if (sb != null)
- {
- subs.UnionWith(sb);
- }
- //abilities.Add(item);
- }
- }
- if (subs.Count > 0 && score >= -1 && score <= 2)
- {
- 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"))
- {
- 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;
- });
- otherScore.tmdid = userid;
- otherScore.tmdname = name;
- otherScore.time = nowTime;
- }
-
- else
- {
- if (sub.uploads.IsNotEmpty() && sub.self > -1)
- {
- 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
- };
- sub.otherScore.Add(otherScore);
- }
- }
- if (sub.uploads.IsEmpty())
- {
- sub.otherScore = new List<OtherScore>();
- }
- abilitySubTasks.Add(client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(sub, sub.id, new PartitionKey(sub.code)));
- });
- (string standard, List<string> tmdid, string school, List<string> update, int statistics) list = ($"{standard}", tmdids, school, new List<string> { StatisticsService.TeacherAbility },0);
- await abilitySubTasks.TaskPage(10);
- await StatisticsService.SendServiceBus(list, _configuration, _serviceBus, client);
- return Ok(new { status = 200 });
- }
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},UpsertSubmitScore/UpsertSubmitScore()\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
- }
- return Ok(new { error = 0, msg = "参数异常" });
- }
- /// <summary>
- /// 对某个订阅的能力点进行操作
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("sub-opt")]
- [Authorize(Roles = "IES")]
- [AuthToken(Roles = "teacher,admin,area")]
- public async Task<IActionResult> SubOpt(JsonElement request)
- {
- try
- {
- if (!HttpContext.Items.TryGetValue("Standard", out object standard)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- if (!request.TryGetProperty("tmdid", out JsonElement _tmdid)) return BadRequest();
- if (!request.TryGetProperty("school", out JsonElement _school)) return BadRequest();
- if (!request.TryGetProperty("opt", out JsonElement _opt)) return BadRequest();
- if (!request.TryGetProperty("abilityId", out JsonElement _abilityId)) return BadRequest();
- string code = $"AbilitySub-{_school}-{_tmdid}";
- int status = 0;
- AbilitySub abilitySub = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<AbilitySub>($"{_abilityId}", new PartitionKey(code));
- Ability abilityA = await client.GetContainer("TEAMModelOS", "Normal").ReadItemAsync<Ability>($"{_abilityId}", new PartitionKey($"Ability-{standard}"));
- switch ($"{_opt}")
- {
- case "ReadSelfOnlineRcd":
- //获取线上学习记录
- return Ok(new { abilitySub.taskRcds });
- case "ReadSomeoneSub":
- //获取线一个人的完整的能力点订阅数据
- var replyIds = abilitySub.otherScore.SelectMany(x => x.replyIds).Where(y=>!string.IsNullOrEmpty(y));
- List<DebateReply> replies = new List<DebateReply>();
- if (replyIds != null && replyIds.Count()>0) {
-
- string sql = $"select value(A1) from c join A1 in c.replies where A1.id in({string.Join(",", replyIds.Select(o => $"'{o}'"))})";
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School")
- .GetItemQueryIteratorSql<DebateReply>(queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Debate-{_school}") }))
- {
- replies.Add(item);
- }
- abilitySub.otherScore.ForEach(x => {
- x.replyIds.RemoveAll(x =>string.IsNullOrEmpty(x) || !replies.Select(r=>r.id).Contains(x));
-
- });
- }
- List<OtherScoreReply> scoreReplies= new List<OtherScoreReply>();
- abilitySub.otherScore.ForEach(x => {
- OtherScoreReply scoreReply = new OtherScoreReply
- {
- roleType=x.roleType,
- tmdid=x.tmdid,
- tmdname=x.tmdname,
- score=x.score,
- scoreUploads=x.scoreUploads,
- time=x.time
- };
- var rs= replies.FindAll(m => x.replyIds.Contains(m.id));
- scoreReply.replies.AddRange(rs);
- scoreReplies.Add(scoreReply);
- });
- Dictionary<string, List<DebateReply>> pairs = new Dictionary<string, List<DebateReply>>();
- abilitySub.otherScore.GroupBy(x => x.roleType).Select(m => new { key= m.Key, list = m.ToList() }).ToList().ForEach(y => {
- var reply= replies.FindAll(z =>y.list.SelectMany(a=>a.replyIds).Contains(z.id));
- pairs.Add(y.key, reply);
- });
- return Ok(new { abilitySub,scoreReplies, ability = abilityA });
- case "SetOnlineDone":
- //完成线上学习
- abilitySub.done = true;
- //abilitySub.abilityCount = abilityA.abilityCount;
- //abilitySub.hour = abilityA.hour;
- await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<AbilitySub>(abilitySub, $"{_abilityId}", new PartitionKey(code));
- return Ok(new { abilitySub });
- case "ExerciseScore":
- //保存自测结果
- if (!request.TryGetProperty("exercise", out JsonElement _exercise)) return BadRequest();
- if (!string.IsNullOrEmpty($"{_exercise}"))
- {
- //exercise -1未自测 0不合格 1 合格
- abilitySub.exerciseScore = int.Parse($"{_exercise}");
- await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<AbilitySub>(abilitySub, $"{_abilityId}", new PartitionKey(code));
- status = 1;
- await StatisticsService.SendServiceBus( ($"{standard}", new List<string> { $"{_tmdid}" }, $"{_school}",new List<string> { StatisticsService.TeacherAbility }, 0) , _configuration, _serviceBus, client);
- return Ok(new { status });
- }
- else
- {
- return BadRequest("参数exercise没有值");
- }
- case "ExerciseRcd":
- //获取自测结果
- return Ok(new { exercise = abilitySub.exerciseScore });
- case "Upload":
- long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
- //上传作品和自评
- if (!request.TryGetProperty("uploads", out JsonElement _uploads)) return BadRequest();
- if (!request.TryGetProperty("self", out JsonElement _self)) return BadRequest();
- List<SubUpload> uploads = _uploads.ToObject<List<SubUpload>>();
- if (!string.IsNullOrEmpty($"{_self}"))
- {
- //_self 0 不及格,1及格,2优秀
- abilitySub.self = int.Parse($"{_self}");
- }
- else
- {
- return BadRequest();
- }
- if (uploads.IsNotEmpty())
- {
- abilitySub.abilityCount = abilityA.abilityCount;
- abilitySub.hour = abilityA.hour;
- uploads.ForEach(u =>
- {
- var up = abilitySub.uploads.Find(x => x.stdid.Equals(u.stdid));
- if (up != null)
- {
- up.urls = u.urls;
- up.taskid = u.taskid;
- up.titleIds = u.titleIds;
- up.time = now;
- }
- else
- {
- u.time = now;
- abilitySub.uploads.Add(u);
- }
- });
- abilitySub.selfTime = now;
- await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<AbilitySub>(abilitySub, $"{_abilityId}", new PartitionKey(code));
- status = 1;
- await StatisticsService.SendServiceBus( ($"{standard}", new List<string> { $"{_tmdid}" }, $"{_school}", new List<string> { StatisticsService.TeacherAbility }, 0) , _configuration, _serviceBus, client);
- }
- else
- {
- return BadRequest();
- }
- return Ok(new { status });
- case "YouRateSomone":
- //你对别人的某个能力点的学习进行评价,不能评价自己的,
- if (!request.TryGetProperty("otherScore", out JsonElement _other)) return BadRequest();
- RoleScore other = _other.ToObject<RoleScore>();
- string replyId = null;
- if (other != null)
- {
- //if (abilitySub.creatorId.Equals(other.tmdid))
- //{
- // return BadRequest("不能评价自己的");
- //}
- long nowTime = DateTimeOffset.Now.ToUnixTimeMilliseconds();
- if (!string.IsNullOrEmpty(other.reply))
- {
- replyId = Guid.NewGuid().ToString();
- DebateReply debateReply = new DebateReply
- {
- atUserType = "tmdid",
- userType = "tmdid",
- id = replyId,
- pid = abilitySub.comid,
- tmdid = other.tmdid,
- tmdname = other.tmdname,
- comment = other.reply,
- atTmdid = $"{_tmdid}",
- atTmdname = other.atTmdname,
- time = nowTime
- };
- try
- {
- Debate debate = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<Debate>(abilitySub.comid, new PartitionKey($"Debate-{_school}"));
- debate.replies.Add(debateReply);
- await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<Debate>(debate, abilitySub.comid, new PartitionKey($"Debate-{_school}"));
- }
- catch (CosmosException ex)
- {
- if (ex.Status == 404)
- {
- Debate debate = new Debate
- {
- userType = "tmdid",
- comid = $"{abilityA.comid}",
- code = $"Debate-{_school}",
- id = $"{abilitySub.comid}",
- tmdid = abilitySub.creatorId,
- tmdname = other.atTmdname,
- title = $"{other.atTmdname}-{abilityA.name}",
- time = nowTime,
- comment = "",
- school = $"{_school}",
- replies = new List<DebateReply>() { debateReply },
- source = "uploadscore",
- openType = 0,
- ttl = -1,
- pk = "Debate"
- };
- await client.GetContainer("TEAMModelOS", "School").CreateItemAsync<Debate>(debate, new PartitionKey($"Debate-{_school}"));
- }
- }
- }
- if (other.roleType.Equals("school"))
- {
- //学校的身份不管是谁,只能以学校的身份进行一次评论
- abilitySub.allDone = true;
- var otherScore = abilitySub.otherScore.Find(x => x.roleType.Equals(other.roleType));
- if (otherScore != null)
- {
- otherScore.tmdid = other.tmdid;
- otherScore.tmdname = other.tmdname;
- otherScore.score = other.score;
- if (!string.IsNullOrEmpty(replyId))
- {
- if (otherScore.replyIds.IsNotEmpty())
- {
- otherScore.replyIds.Add(replyId);
- }
- else
- {
- otherScore.replyIds = new List<string>() { replyId };
- }
- }
- otherScore.scoreUploads = other.scoreUploads;
- otherScore.time = nowTime;
- }
- else
- {
- abilitySub.otherScore.Add(new OtherScore
- {
- roleType = other.roleType,
- tmdid = other.tmdid,
- tmdname = other.tmdname,
- score = other.score,
- replyIds = new List<string>() { replyId },
- scoreUploads = other.scoreUploads,
- time = nowTime
- });
- }
- }
- else if (other.roleType.Equals("leader"))
- {
- //小组评的身份不管是谁,只能以学校的身份进行一次评论
- abilitySub.allDone = true;
- var otherScore = abilitySub.otherScore.Find(x => x.roleType.Equals(other.roleType));
- if (otherScore != null)
- {
- otherScore.tmdid = other.tmdid;
- otherScore.tmdname = other.tmdname;
- otherScore.score = other.score;
- if (!string.IsNullOrEmpty(replyId))
- {
- if (otherScore.replyIds.IsNotEmpty())
- {
- otherScore.replyIds.Add(replyId);
- }
- else
- {
- otherScore.replyIds = new List<string>() { replyId };
- }
- }
- otherScore.scoreUploads = other.scoreUploads;
- otherScore.time = nowTime;
- }
- else
- {
- abilitySub.otherScore.Add(new OtherScore
- {
- roleType = other.roleType,
- tmdid = other.tmdid,
- tmdname = other.tmdname,
- score = other.score,
- replyIds = new List<string>() { replyId },
- scoreUploads = other.scoreUploads,
- time = nowTime
- });
- }
- }
- else
- {
- //其他身份的同一个人可以以不同身份进行点评
- var otherScore = abilitySub.otherScore.Find(x => x.tmdid.Equals(other.tmdid) && x.roleType.Equals(other.roleType));
- if (otherScore != null)
- {
- otherScore.tmdid = other.tmdid;
- otherScore.tmdname = other.tmdname;
- otherScore.score = other.score;
- if (!string.IsNullOrEmpty(replyId))
- {
- if (otherScore.replyIds.IsNotEmpty())
- {
- otherScore.replyIds.Add(replyId);
- }
- else
- {
- otherScore.replyIds = new List<string>() { replyId };
- }
- }
- otherScore.scoreUploads = other.scoreUploads;
- otherScore.time = nowTime;
- }
- else
- {
- abilitySub.otherScore.Add(new OtherScore
- {
- roleType = other.roleType,
- tmdid = other.tmdid,
- tmdname = other.tmdname,
- score = other.score,
- replyIds = new List<string>() { replyId },
- scoreUploads = other.scoreUploads,
- time = nowTime
- });
- }
- }
- await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<AbilitySub>(abilitySub, $"{_abilityId}", new PartitionKey(code));
- await StatisticsService.SendServiceBus( ($"{standard}",new List<string> { $"{_tmdid}" }, $"{_school}", new List<string> { StatisticsService.TeacherAbility }, 0) , _configuration, _serviceBus, client);
- status = 1;
- }
- return Ok(new { status, abilitySub });
- case "YouGetSomoneRate":
- //你获取你对别人的某个能力点的学习评价
- OtherScore score = null;
- if (!request.TryGetProperty("yourTmdid", out JsonElement _yourTmdid)) return BadRequest();
- if (string.IsNullOrEmpty($"{_yourTmdid}"))
- {
- score = abilitySub.otherScore.Find(x => x.tmdid.Equals($"{_yourTmdid}"));
- if (score != null)
- {
- status = 1;
- return Ok(new { score, status });
- }
- else
- {
- return Ok(new { status, score });
- }
- }
- else
- {
- return Ok(new { status, score });
- }
- case "SaveLearnOnlineRcd":
- //保存线上学习记录
- if (!request.TryGetProperty("taskRcds", out JsonElement _taskRcds)) return BadRequest();
- AbilityTaskRcd taskRcds = _taskRcds.ToObject<AbilityTaskRcd>();
- if (taskRcds != null)
- {
- bool isnew = true;
- abilitySub.taskRcds.ForEach(x =>
- {
- if (x.id.Equals(taskRcds.id))
- {
- //重新上传或者覆盖之前
- x.done = taskRcds.done;
- x.urls = taskRcds.urls;
- isnew = false;
- }
- });
- if (isnew)
- {
- abilitySub.taskRcds.Add(taskRcds);
- }
- await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<AbilitySub>(abilitySub, $"{_abilityId}", new PartitionKey(code));
- status = 1;
- }
- return Ok(new { status, abilitySub.taskRcds });
- case "SaveVideoRcd":
- //保存线上学习记录
- if (!request.TryGetProperty("videoRcd", out JsonElement _videoRcd)) return BadRequest();
- AbilityVideoRcd videoRcd = _videoRcd.ToObject<AbilityVideoRcd>();
- if (videoRcd != null)
- {
- bool isnew = true;
- abilitySub.videoRcds.ForEach(x =>
- {
- if (x.abilityId.Equals(videoRcd.abilityId) && x.abilityTaskId.Equals(videoRcd.abilityTaskId) && x.url.Equals(videoRcd.url))
- {
- //重新上传或者覆盖之前
- x.done = videoRcd.done;
- x.time = videoRcd.time;
- isnew = false;
- }
- });
- if (isnew)
- {
- abilitySub.videoRcds.Add(videoRcd);
- }
- await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<AbilitySub>(abilitySub, $"{_abilityId}", new PartitionKey(code));
- status = 1;
- }
- return Ok(new { status, abilitySub.videoRcds });
- case "SaveFileRcd":
- //保存文件学习记录
- if (!request.TryGetProperty("fileRcd", out JsonElement _fileRcd)) return BadRequest();
- List< TeacherFileRcd > fileRcds = new List< TeacherFileRcd >();
- if (_fileRcd.ValueKind.Equals(JsonValueKind.Object))
- {
- TeacherFileRcd fileRcd = _fileRcd.ToObject<TeacherFileRcd>();
- fileRcds.Add( fileRcd );
- }
- else if (_fileRcd.ValueKind.Equals(JsonValueKind.Array))
- {
- fileRcds = _fileRcd.ToObject<List<TeacherFileRcd>>();
- }
- fileRcds.ForEach(x => {
- if (x.done && x.type.Equals("video")) {
- x.view = (int)x.duration;
- }
- });
- TeacherFile teacherFile = null;
- try
- {
- teacherFile = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<TeacherFile>($"{_tmdid}", new PartitionKey($"TeacherFile-{_school}"));
- fileRcds.ForEach(fileRcd =>
- {
- var file = teacherFile.fileRecords.Find(x => x.hash.Equals(fileRcd.hash));
- if (file != null)
- {
- file.hash = fileRcd.hash;
- file.view = fileRcd.view;
- file.done = fileRcd.done;
- FileAbility ability = file.files.Find(x => x.abilityId.Equals(fileRcd.abilityId)
- && x.url.Equals(fileRcd.url) && x.taskId.Equals(fileRcd.taskId)
- && x.nodeId.Equals(fileRcd?.nodeId));
- if (ability != null)
- {
- ability.url = fileRcd.url;
- ability.abilityId = fileRcd.abilityId;
- ability.taskId = fileRcd.taskId;
- ability.nodeId = fileRcd.nodeId;
- }
- else
- {
- file.files.Add(new FileAbility { url = fileRcd.url, abilityId = fileRcd.abilityId, taskId = fileRcd.taskId, nodeId = fileRcd.nodeId, });
- }
- }
- else
- {
- teacherFile.fileRecords.Add(new FileRecord
- {
- hash = fileRcd.hash,
- size = fileRcd.size,
- duration = fileRcd.duration,
- view = fileRcd.view,
- type = fileRcd.type,
- done = fileRcd.done,
- files = new List<FileAbility> { new FileAbility { url = fileRcd.url, abilityId = fileRcd.abilityId, taskId = fileRcd.taskId, nodeId = fileRcd.nodeId, } }
- });
- }
- });
- await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<TeacherFile>(teacherFile, teacherFile.id, new PartitionKey($"TeacherFile-{_school}"));
- }
- catch (CosmosException)
- {
- fileRcds.ForEach(fileRcd =>
- {
- teacherFile = new TeacherFile
- {
- pk = "TeacherFile",
- id = $"{_tmdid}",
- code = $"TeacherFile-{_school}",
- fileRecords = new List<FileRecord>
- {
- new FileRecord
- {
- hash= fileRcd.hash,
- size=fileRcd.size,
- duration=fileRcd.duration,
- view=fileRcd.view,
- type=fileRcd.type,
- done=fileRcd.done,
- files= new List<FileAbility> { new FileAbility { url=fileRcd.url,abilityId=fileRcd.abilityId,taskId=fileRcd.taskId,nodeId=fileRcd.nodeId} }
- }
- },
- };
- });
- await client.GetContainer("TEAMModelOS", "Teacher").CreateItemAsync<TeacherFile>(teacherFile, new PartitionKey($"TeacherFile-{_school}"));
- }
- catch (Exception ex ){
- return BadRequest();
- }
- if (fileRcds.Exists(x => x.type.Equals("video"))) {
- await StatisticsService.SendServiceBus( ($"{standard}",new List<string> { $"{_tmdid}" }, $"{_school}", new List<string> { StatisticsService.TeacherAbility },0) , _configuration, _serviceBus, client);
- }
- //获取视文件学习记录
- List<dynamic> _files = new List<dynamic>();
- List<dynamic> abilityView = new List<dynamic>();
- try
- {
- TeacherFile teacherFilercd = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<TeacherFile>($"{_tmdid}", new PartitionKey($"TeacherFile-{_school}"));
- teacherFilercd.fileRecords.ForEach(x => {
- var file = x.files.FindAll(y => y.abilityId.Equals($"{_abilityId}"));
- if (file.IsNotEmpty())
- {
- _files.Add(new { ability = file, view = x.view, hash = x.hash, done = x.done });
- }
- });
- if (teacherFilercd != null)
- {
- HashSet<string> abilityIds = teacherFilercd.fileRecords.SelectMany(x => x.files).Select(x => x.abilityId).ToHashSet();
- foreach (var abid in abilityIds)
- {
- var record = teacherFilercd.fileRecords.FindAll(x => x.files.Where(y => y.abilityId.Equals(abid)).Count() > 0);
- double view = 0;
- List<dynamic> urls = new List<dynamic>();
- record.ForEach(x => {
- var file = x.files.FindAll(y => y.abilityId.Equals($"{abid}"));
- if (file.IsNotEmpty())
- {
- view += x.view;
- urls.Add(new { ability = file, view = x.view, hash = x.hash, done = x.done });
- }
- });
- abilityView.Add(new { view, abilityId = abid });
- }
- }
- }
- catch (Exception ex)
- {
- return BadRequest(ex);
- }
- return Ok(new { status, files=_files, abilityFiles = abilityView });
- case "ReadSelfVideoRcd":
- //获取视频学习记录
- return Ok(new { abilitySub.videoRcds });
- case "ReadSelfFileRcd":
- //获取视文件学习记录
- List<dynamic> files = new List<dynamic>();
- List<dynamic> abilityFiles = new List<dynamic>();
- try {
- TeacherFile teacherFilercd = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<TeacherFile>($"{_tmdid}", new PartitionKey($"TeacherFile-{_school}"));
- HashSet<string> abilityIds= teacherFilercd.fileRecords.SelectMany(x => x.files).Select(x => x.abilityId).ToHashSet() ;
- teacherFilercd.fileRecords.ForEach(x => {
- var file = x.files.FindAll(y => y.abilityId.Equals($"{_abilityId}"));
- if (file.IsNotEmpty()) {
- files.Add(new { ability =file,view=x.view,hash=x.hash,done=x.done });
- }
- });
- foreach (var abid in abilityIds) {
- var record= teacherFilercd.fileRecords.FindAll(x => x.files.Where(y => y.abilityId.Equals(abid)).Count() > 0);
- double view = 0;
- List<dynamic> urls = new List<dynamic>();
- record.ForEach(x => {
- var file= x.files.FindAll(y => y.abilityId.Equals($"{abid}"));
- if (file.IsNotEmpty())
- {
- view += x.view;
- urls.Add(new { ability = file, view = x.view, hash = x.hash, done = x.done });
- }
- });
- abilityFiles.Add(new { view, abilityId= abid });
- }
- return Ok(new { status, files, abilityFiles });
- } catch (Exception ex) {
-
- }
- return Ok(new { });
- case "ReadFileHashRcd":
- //获取视文件学习记录
- List<FileRecord> fileRecords = new List<FileRecord>();
- if (!request.TryGetProperty("hashes", out JsonElement _hashes)) return BadRequest();
- List<string> hashes = _hashes.ToObject<List<string>>();
- if (hashes.IsNotEmpty())
- {
- string sql = $"SELECT value(a) FROM c join a in c.fileRecords where a.hash in({string.Join(",", hashes.Select(x => $"'{x}'"))}) and c.id='{_tmdid}' and a.type='video'";
- await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").
- GetItemQueryIteratorSql<FileRecord>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"TeacherFile-{_school}") }))
- {
- fileRecords.Add(item);
- }
- }
- return Ok(new { status, fileRecords });
- default:
- return Ok(new { status = -1 });
- }
- }
- catch (CosmosException ex)
- {
- return Ok(new { status = -1 });
- }
- catch (Exception ex)
- {
- #if DEBUG
- await _dingDing.SendBotMsg($"OS,{_option.Location},AbilityController/SubOpt()\n{ex.Message}\n{ex.StackTrace}{request.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
- #else
- #endif
- return Ok(new { status = -1 });
- }
- } /// <summary>
- /// 获取回复详情信息。
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-reply-info")]
- [Authorize(Roles = "IES")]
- [AuthToken(Roles = "teacher,admin,area")]
- public async Task<IActionResult> GetReplyInfo(JsonElement request)
- {
- if (!request.TryGetProperty("school", out JsonElement _school)) return BadRequest();
- if (!request.TryGetProperty("replyIds", out JsonElement _replyIds)) return BadRequest();
- List<string> replyIds = _replyIds.ToObject<List<string>>();
- if (replyIds.IsNotEmpty())
- {
- List<dynamic> replies = new List<dynamic>();
- string sql = $"select A1 as replies from c join A1 in c.replies where A1.id in({string.Join(",", replyIds.Select(o => $"'{o}'"))})";
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School")
- .GetItemQueryIteratorSql<dynamic>(queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Debate-{_school}") }))
- {
- replies.Add(item);
- }
- return Ok(new { replies });
- }
- return Ok();
- }
- /// <summary>
- /// 获取订阅了相同的能力点的教师。
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-same-subs")]
- [Authorize(Roles = "IES")]
- [AuthToken(Roles = "teacher,admin,area")]
- public async Task<IActionResult> GetSameSubs(JsonElement request)
- {
- // (string id, _, _, string school) = HttpContext.GetAuthTokenInfo();
- if (!request.TryGetProperty("school", out JsonElement _school))
- {
- return Ok(new { error = 400 });
- }
- var client = _azureCosmos.GetCosmosClient();
- if (!request.TryGetProperty("tmdid", out JsonElement _tmdid)) return Ok(new { error = 400 });
- if (!request.TryGetProperty("abilityId", out JsonElement _abilityId)) return Ok(new { error = 400 });
- List<RGroupList> yxtrain= await GroupListService.GetGroupListMemberByType(_coreAPIHttpService, client, "yxtrain", new List<string> { "school" }, $"{_school}",_dingDing);
- List<dynamic> abilitySubs = new List<dynamic>();
- if (yxtrain.IsNotEmpty()) {
- var members = yxtrain.SelectMany(m => m.members).ToList();
- List<RMember> tmdids = members.FindAll(x => x.type == 1).Where((x, i) => members.FindAll(x => x.type == 1).FindIndex(n => n.id.Equals(x.id)) == i).ToList();
- tmdids= tmdids.FindAll(x => !x.id.Equals($"{_tmdid}"));
- await foreach ((RMember tmdid, JsonElement sub) in GetSubsAsyn(tmdids, $"{_tmdid}", $"{_abilityId}", $"{_school}")) {
- AbilitySub abilitySub= sub.ToObject<AbilitySub>();
- if (abilitySub.uploads.IsNotEmpty()) {
- abilitySubs.Add(new { tmdid, sub= abilitySub });
- }
-
- }
- }
- return Ok(new { abilitySubs });
- }
- private async IAsyncEnumerable<(RMember, JsonElement)> GetSubsAsyn(List<RMember> tmdids,string _tmdid ,string _abilityId,string _school) {
- foreach (var tmdid in tmdids)
- {
- Response subs = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync($"{_abilityId}", new PartitionKey($"AbilitySub-{_school}-{tmdid.id}"));
- if (subs.StatusCode==System.Net.HttpStatusCode.OK) {
- var json = await JsonDocument.ParseAsync(subs.Content);
- JsonElement element =json.RootElement;
- yield return (tmdid, element);
- }
- }
- }
- /// <summary>
- /// 获取本小组的订阅
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-group-subs")]
- [Authorize(Roles = "IES")]
- [AuthToken(Roles = "teacher,admin,area")]
- public async Task<IActionResult> GetGroupSubs(JsonElement request)
- {
- try
- {
- if (!HttpContext.Items.TryGetValue("Standard", out object standard)) return Ok(new { error = 400 });
- // (string id, _, _, string school) = HttpContext.GetAuthTokenInfo();
- string school = "";
- if (!request.TryGetProperty("school", out JsonElement _school))
- {
- return Ok(new { error = 400 });
- }
- else
- {
- school = $"{_school}";
- }
- var client = _azureCosmos.GetCosmosClient();
- if (!request.TryGetProperty("tmdid", out JsonElement _tmdid)) return Ok(new { error = 400 });
- request.TryGetProperty("all", out JsonElement _all);
- List<Ability> abilities = new List<Ability>();
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Normal")
- .GetItemQueryIteratorSql<Ability>(queryText: $"select value(c) from c where c.status = 1 ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Ability-{standard}") }))
- {
- abilities.Add(item);
- }
- //List<ScTeacher> teachers = new List<ScTeacher>();
- //await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIteratorSql<ScTeacher>(queryText: $"SELECT c.groupName,c.groupId, c.id, c.name, c.picture FROM c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{school}") }))
- //{
- // if (string.IsNullOrEmpty(item.groupId))
- // {
- // item.groupId = "default";
- // item.groupName = "默认组别";
- // }
- // teachers.Add(item);
- //}
- List<GroupList> tchLists = new List<GroupList>();
- await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIteratorSql<GroupList>(queryText: $"SELECT value(c) FROM c where c.type='yxtrain' ",
- requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"GroupList-{_school}") }))
- {
- tchLists.Add(item);
- }
- List<string> ids = tchLists.Select(x => x.id).ToList();
- if (!ids.IsNotEmpty())
- {
- ids.Add("default");
- }
- (List<RMember> tmdInfos, List<RGroupList> classInfos) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, ids, $"{_school}");
- List<GroupMember> teachers = new List<GroupMember>();
- foreach (var classInfo in classInfos)
- {
- foreach (var tmdinfo in classInfo.members)
- {
- teachers.Add(new GroupMember { nickname = tmdinfo.nickname, groupId = classInfo.id, groupName = classInfo.name, tmdid = tmdinfo.id, tmdname = tmdinfo.name, picture = tmdinfo.picture, tag = tmdinfo.tag });
- }
- }
- if ($"{_all}".Equals("1"))
- {
- List<SubGroupMember> groupMembers = new List<SubGroupMember>();
- // List<Debate> debates = new List<Debate>();
- // HashSet<string> comids = new HashSet<string>();
- foreach (var t in teachers)
- {
- try
- {
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher")
- .GetItemQueryIteratorSql<AbilitySub>(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AbilitySub-{school}-{t.tmdid}") }))
- {
- // comids.Add(item.comid);
- groupMembers.Add(new SubGroupMember
- {
- nickname = t.nickname,
- tmdname = t.tmdname,
- tmdid = t.tmdid,
- picture = t.picture,
- groupName = t.groupName,
- groupId = t.groupId,
- sub = new SubGroup
- {
- abilityId = item.id,
- code = item.code,
- uploads = item.uploads,
- otherScore = item.otherScore,
- comid = item.comid,
- self = item.self
- }
- });
- }
- }
- catch (CosmosException ex) { }
- }
- return Ok(new { groupMembers, abilities });
- }
- else
- {
- var teacer = teachers.FindAll(x => x.tmdid.Equals($"{_tmdid}"));
- if (teacer != null)
- {
- List<SubGroupMember> groupMembers = new List<SubGroupMember>();
- var tecs = teachers.Where(x => teacer.Select(y => y.groupId).Contains(x.groupId)).ToList();
- foreach (var t in tecs)
- {
- //排除自己,如果不是组长则不排除
- if (t.tmdid.Equals($"{_tmdid}") && string.IsNullOrEmpty(t.tag)) { continue; }
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher")
- .GetItemQueryIteratorSql<AbilitySub>(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AbilitySub-{school}-{t.tmdid}") }))
- {
- groupMembers.Add(new SubGroupMember
- {
- nickname = t.nickname,
- tmdname = t.tmdname,
- tmdid = t.tmdid,
- picture = t.picture,
- groupName = t.groupName,
- groupId = t.groupId,
- sub = new SubGroup
- {
- abilityId = item.id,
- code = item.code,
- uploads = item.uploads,
- otherScore = item.otherScore,
- comid = item.comid,
- self = item.self
- },
- tag = t.tag
- });
- }
- }
- return Ok(new { groupMembers, abilities });
- }
- else
- {
- return Ok(new { error = 400 });
- }
- }
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"OS,{_option.Location},AbilityController/SaveSubs()\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
- return Ok(new { error = 400 });
- }
- }
- public class GroupMember
- {
- public string tmdname { get; set; }
- public string tmdid { get; set; }
- public string picture { get; set; }
- public string groupName { get; set; }
- public string groupId { get; set; }
- public string tag { get; set; }
- public string nickname { get; set; }
- }
- public class SubGroupMember
- {
- public string nickname { get; set; }
- public string tmdname { get; set; }
- public string tmdid { get; set; }
- public string picture { get; set; }
- public string groupName { get; set; }
- public string groupId { get; set; }
- public SubGroup sub { get; set; }
- public string tag { get; set; }
- }
- public class SubGroup
- {
- public string comid { get; set; }
- public int self { get; set; }
- public string abilityId { get; set; }
- public string code { get; set; }
- public List<SubUpload> uploads { get; set; }
- public List<OtherScore> otherScore { get; set; }
- }
- public class RoleScore
- {
- /// <summary>
- /// 角色类型 成员 member 学校 school 专家 expert
- /// </summary>
- public string roleType { get; set; }
- /// <summary>
- /// 评论人的id
- /// </summary>
- public string tmdid { get; set; }
- /// <summary>
- /// 评论人
- /// </summary>
- public string tmdname { get; set; }
- /// <summary>
- /// 被评论人的醍摩豆名称
- /// </summary>
- public string atTmdname { get; set; }
- //总评 -1未评,0未通过,1合格,2优秀
- public int score { get; set; } = -1;
- /// <summary>
- /// 某人对你这个能力点的学习评价的的评语记录的Id集合。
- /// </summary>
- public string reply { get; set; }
- /// <summary>
- /// 根据评判标准进行打分
- /// </summary>
- public List<ScoreUpload> scoreUploads { get; set; } = new List<ScoreUpload>();
- }
- }
- }
|