12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313 |
-
- using 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 HTEXLib.COMM.Helpers;
- using TEAMModelOS.Filter;
- using Azure;
- using Azure.Messaging.ServiceBus;
- using Microsoft.Extensions.Configuration;
- using Microsoft.AspNetCore.Authorization;
- 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 ThirdApisService _thirdApisService;
- private readonly HttpTrigger _httpTrigger;
- private readonly AzureServiceBusFactory _serviceBus;
- private readonly AzureStorageFactory _azureStorage;
- private readonly CoreAPIHttpService _coreAPIHttpService;
- public IConfiguration _configuration { get; set; }
- public AbilitySubController(CoreAPIHttpService coreAPIHttpService, AzureStorageFactory azureStorage,AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option, ThirdApisService thirdApisService, HttpTrigger httpTrigge, AzureServiceBusFactory serviceBus, IConfiguration configuration)
- {
- _azureCosmos = azureCosmos;
- _snowflakeId = snowflakeId;
- _dingDing = dingDing;
- _option = option?.Value;
- _thirdApisService = thirdApisService;
- _httpTrigger = httpTrigge;
- _serviceBus = serviceBus;
- _configuration = configuration;
- _azureStorage = azureStorage;
- _coreAPIHttpService = coreAPIHttpService;
- }
-
- /// <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")
- .GetItemQueryIterator<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")
- .GetItemQueryIterator<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, _httpTrigger, 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")
- .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")]
- [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")
- .GetItemQueryIterator<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")
- .GetItemQueryIterator<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").
- GetItemQueryIterator<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")
- .GetItemQueryIterator<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.Status==200) {
- var json = await JsonDocument.ParseAsync(subs.ContentStream);
- 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")
- .GetItemQueryIterator<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").GetItemQueryIterator<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").GetItemQueryIterator<GroupList>(queryText: $"SELECT value(c) FROM c where c.type='research' ",
- 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")
- .GetItemQueryIterator<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")
- .GetItemQueryIterator<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>();
- }
- }
- }
|