123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077 |
- using Azure.Cosmos;
- using Azure.Messaging.ServiceBus;
- using HTEXLib.COMM.Helpers;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.Configuration;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Extension;
- using TEAMModelOS.SDK.Models;
- using TEAMModelOS.SDK.Models.Service;
- namespace TEAMModelOS.SDK
- {
- public static class StatisticsService
- {
- /// <summary>
- /// 教师能力点操作
- /// </summary>
- public const string TeacherAbility = "TeacherAbility";
- /// <summary>
- /// 课堂实录
- /// </summary>
- public const string TeacherClass = "TeacherClass";
- /// <summary>
- /// 线下研修
- /// </summary>
- public const string OfflineRecord = "OfflineRecord";
- /// <summary>
- /// 教师投票活动
- /// </summary>
- public const string TeacherVote = "TeacherVote";
- /// <summary>
- /// 教师作业活动
- /// </summary>
- public const string TeacherHomework = "TeacherHomework";
- /// <summary>
- /// 教师问卷活动
- /// </summary>
- public const string TeacherSurvey = "TeacherSurvey";
- /// <summary>
- /// 教师评测活动
- /// </summary>
- public const string TeacherExamLite = "TeacherExamLite";
- public static async Task DoChange(TeacherTrainChange change, AzureCosmosFactory _azureCosmos)
- {
- if (change.tmdids.IsNotEmpty() && change.update.Count() > 0 && !string.IsNullOrEmpty(change.school))
- {
- var client = _azureCosmos.GetCosmosClient();
- string insql = $"where c.id in ({string.Join(",", change.tmdids.Select(x => $"'{x}'"))})";
- string selsql = $"select value(c) from c {insql} ";
- List<TeacherTrain> teacherTrains = new List<TeacherTrain>();
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<TeacherTrain>(queryText: selsql,
- requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"TeacherTrain-{change.school}") }))
- {
- teacherTrains.Add(item);
- }
- List<Task<ItemResponse<TeacherTrain>>> task = new List<Task<ItemResponse<TeacherTrain>>>();
- teacherTrains.ForEach(x => {
- change.update.ToList().ForEach(u => {
- x.update.Add(u);
- });
- task.Add(client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<TeacherTrain>(x, x.id, new PartitionKey($"TeacherTrain-{change.school}")));
- });
- await task.TaskPage(5);
- var unchange = change.tmdids.Except(teacherTrains.Select(x => x.id));
- if (unchange != null)
- {
- task.Clear();
- unchange.ToList().ForEach(x => {
- TeacherTrain teacherTrain = new TeacherTrain
- {
- pk = "TeacherTrain",
- id = x,
- code = $"TeacherTrain-{change.school}",
- tmdid = x,
- school = change.school,
- update = new HashSet<string> { StatisticsService.TeacherAbility,
- StatisticsService.TeacherClass, StatisticsService.OfflineRecord }
- };
- change.update.ToList().ForEach(u => {
- teacherTrain.update.Add(u);
- });
- task.Add(client.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<TeacherTrain>(teacherTrain, new PartitionKey($"TeacherTrain-{change.school}")));
- });
- await task.TaskPage(5);
- }
- }
- }
- public static async Task SendServiceBus((string standard, List<string> tmdids, string school, List<string> update, int statistics) list, IConfiguration _configuration, AzureServiceBusFactory _serviceBus, CosmosClient client)
- {
- if (list.tmdids.IsNotEmpty() && list.update.IsNotEmpty())
- {
- string insql = $"where c.id in ({string.Join(",", list.tmdids.Select(x => $"'{x}'"))})";
- string selsql = $"select value(c) from c {insql} ";
- List<TeacherTrain> teacherTrains = new List<TeacherTrain>();
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<TeacherTrain>(queryText: selsql,
- requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"TeacherTrain-{list.school}") }))
- {
- teacherTrains.Add(item);
- }
- List<Task<ItemResponse<TeacherTrain>>> task = new List<Task<ItemResponse<TeacherTrain>>>();
- teacherTrains.ForEach(x => {
- list.update.ForEach(u => {
- x.update.Add(u);
- });
- task.Add(client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<TeacherTrain>(x, x.id, new PartitionKey($"TeacherTrain-{list.school}")));
- });
- await task.TaskPage(5);
- var unchange = list.tmdids.Except(teacherTrains.Select(x => x.id));
- if (unchange != null)
- {
- task.Clear();
- unchange.ToList().ForEach(x => {
- TeacherTrain teacherTrain = new TeacherTrain
- {
- pk = "TeacherTrain",
- id = x,
- code = $"TeacherTrain-{list.school}",
- tmdid = x,
- school = list.school,
- update = new HashSet<string> { StatisticsService.TeacherAbility,
- StatisticsService.TeacherClass, StatisticsService.OfflineRecord }
- };
- list.update.ForEach(u => {
- teacherTrain.update.Add(u);
- });
-
- task.Add(client.GetContainer(Constant.TEAMModelOS, "Teacher").UpsertItemAsync<TeacherTrain>(teacherTrain, new PartitionKey($"TeacherTrain-{list.school}")));
- });
- await task.TaskPage(1);
- }
- }
- }
- public static async Task GetAreaAndAreaSetting(string schoolId, string _standard, CosmosClient client, HttpContext httpContext)
- {
- School school = null;
- AreaSetting setting = null;
- string standard = "";
- if (string.IsNullOrEmpty(_standard))
- {
- standard = _standard;
- }
- else if (!string.IsNullOrEmpty(schoolId))
- {
- //优先找校级
- setting = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<AreaSetting>(schoolId, new PartitionKey("AreaSetting"));
- //优先找校级
- school = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(schoolId, new PartitionKey("Base"));
- }
- }
- //public static async Task<List<(List<TeacherTrain> trains, List<RGroupList> yxtrain)>> StatisticsArea(CoreAPIHttpService _coreAPIHttpService, AreaSetting setting, Area area, CosmosClient client, DingDing _dingDing, HashSet<string> updates)
- //{
- // List<(List<TeacherTrain> trains, List<RGroupList> yxtrain)> teacherTrains = new List<(List<TeacherTrain> trains, List<RGroupList> yxtrain)>();
- // List<School> schools = new List<School>();
- // await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School")
- // .GetItemQueryIterator<School>(queryText: $"select value(c) from c where c.areaId='{area.id}' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
- // {
- // schools.Add(item);
- // }
- // await foreach ((List<TeacherTrain> trains, List<RGroupList> yxtrain) tarain in GetStatisticsSchool(_coreAPIHttpService, schools, setting, area, client, _dingDing, updates))
- // {
- // teacherTrains.Add(tarain);
- // }
- // return teacherTrains;
- //}
- //private static async IAsyncEnumerable<(List<TeacherTrain> trains, List<RGroupList> yxtrain)> GetStatisticsSchool(CoreAPIHttpService _coreAPIHttpService,List<School> schools, AreaSetting setting, Area area, CosmosClient client, DingDing _dingDing, HashSet<string> updates)
- //{
- // foreach (var school in schools)
- // {
- // yield return await StatisticsSchool( _coreAPIHttpService,school.id, setting, area, client, _dingDing, updates);
- // }
- //}
- public static async Task<(List<TeacherTrain> trains, List<RGroupList> yxtrain)> StatisticsSchoolQuik(CoreAPIHttpService _coreAPIHttpService, string school, AreaSetting setting, Area area, CosmosClient client, DingDing _dingDing, HashSet<string> updates)
- {
- _coreAPIHttpService.check = false;
- List<RGroupList> yxtrain = await GroupListService.GetGroupListMemberByType(_coreAPIHttpService, client, "yxtrain", new List<string> { "school" }, $"{school}", _dingDing);
- List<TeacherTrain> trains = new List<TeacherTrain>();
- var members = yxtrain.SelectMany(x => x.members).ToList();
- if (members.Count <= 0)
- {
- return (trains, yxtrain);
- }
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher")
- .GetItemQueryIterator<TeacherTrain>(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"TeacherTrain-{school}") }))
- {
- trains.Add(item);
- }
- if (updates != null)
- {
- foreach (var up in updates)
- {
- trains.ForEach(x => x.update.Add(up));
- }
- }
- var update = trains.FindAll(x => x.update.Count() > 0);
- var noupdate = trains.FindAll(x => x.update.Count() <= 0);
- var unStatistics = members.Select(x => x.id).Except(trains.Select(x => x.id));
- List<TeacherTrain> teacherTrains = new List<TeacherTrain>();
- List<TeacherTrain> returnTrains = new List<TeacherTrain>();
- if (update.IsNotEmpty())
- {
- teacherTrains.AddRange(update);
- }
- if (unStatistics != null)
- {
- foreach (string x in unStatistics)
- {
- var member = members.Find(y => y.id.Equals(x));
- teacherTrains.Add(new TeacherTrain
- {
- pk = "TeacherTrain",
- id = x,
- code = $"TeacherTrain-{school}",
- tmdid = x,
- nickname = member.nickname,
- name = member.name,
- picture = member.picture,
- school = school,
- update = new HashSet<string> { TeacherAbility, TeacherClass, OfflineRecord }
- });
- }
- }
- List<Study> studies = new List<Study>();
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common")
- .GetItemQueryIterator<Study>(queryText: $"select value(c) from c where c.owner<>'area' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Study-{school}") }))
- {
- studies.Add(item);
- }
- returnTrains = teacherTrains;// await GetStatisticsTeacher(teacherTrains, setting, area, client, studies);
- //await foreach (var tarain in GetStatisticsTeacher(teacherTrains, setting, area, client))
- //{
- // returnTrains.Add(tarain);
- //}
- if (noupdate.IsNotEmpty())
- {
- returnTrains.AddRange(noupdate);
- }
- //移除不在研修名单的人员
- returnTrains.RemoveAll(x => !members.Select(y => y.id).Contains(x.id));
- returnTrains.ForEach(x => {
- var mbm = members.Find(y => y.id.Equals(x.id));
- if (mbm != null)
- {
- x.groupName = mbm?.groupName;
- x.name = !string.IsNullOrWhiteSpace(x.name) ? x.name : mbm?.name;
- x.nickname = mbm?.nickname;
- x.picture = mbm?.picture;
- }
- });
- return (returnTrains, yxtrain);
- }
- public static async Task<(List<TeacherTrain> trains, List<RGroupList> yxtrain)> StatisticsSchool(CoreAPIHttpService _coreAPIHttpService,string school, AreaSetting setting, Area area, CosmosClient client, DingDing _dingDing, HashSet<string> updates)
- {
- _coreAPIHttpService.check = false;
-
- List<RGroupList> yxtrain = await GroupListService.GetGroupListMemberByType(_coreAPIHttpService, client, "yxtrain", new List<string> { "school" }, $"{school}", _dingDing);
- List<TeacherTrain> trains = new List<TeacherTrain>();
- var members = yxtrain.SelectMany(x => x.members).ToList();
- if (members.Count <= 0)
- {
- return (trains, yxtrain);
- }
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher")
- .GetItemQueryIterator<TeacherTrain>(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"TeacherTrain-{school}") }))
- {
- trains.Add(item);
- }
- if (updates != null)
- {
- foreach (var up in updates)
- {
- trains.ForEach(x => x.update.Add(up));
- }
- }
- var update = trains.FindAll(x => x.update.Count() > 0);
- var noupdate = trains.FindAll(x => x.update.Count() <= 0);
- var unStatistics = members.Select(x => x.id).Except(trains.Select(x => x.id));
- List<TeacherTrain> teacherTrains = new List<TeacherTrain>();
- List<TeacherTrain> returnTrains = new List<TeacherTrain>();
- if (update.IsNotEmpty())
- {
- teacherTrains.AddRange(update);
- }
- if (unStatistics != null)
- {
- foreach (string x in unStatistics)
- {
- var member = members.Find(y => y.id.Equals(x));
- teacherTrains.Add(new TeacherTrain
- {
- pk = "TeacherTrain",
- id = x,
- code = $"TeacherTrain-{school}",
- tmdid = x,
- nickname=member.nickname,
- name = member.name,
- picture = member.picture,
- school = school,
- update = new HashSet<string> { TeacherAbility, TeacherClass, OfflineRecord }
- });
- }
- }
- List<Study> studies = new List<Study>();
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common")
- .GetItemQueryIterator<Study>(queryText: $"select value(c) from c where c.owner<>'area' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Study-{school}") }))
- {
- studies.Add(item);
- }
- returnTrains = await GetStatisticsTeacher(teacherTrains, setting, area, client, studies);
- //await foreach (var tarain in GetStatisticsTeacher(teacherTrains, setting, area, client))
- //{
- // returnTrains.Add(tarain);
- //}
- if (noupdate.IsNotEmpty())
- {
- returnTrains.AddRange(noupdate);
- }
- //移除不在研修名单的人员
- returnTrains.RemoveAll(x => !members.Select(y => y.id).Contains(x.id));
- returnTrains.ForEach(x => {
- var mbm = members.Find(y => y.id.Equals(x.id));
- if (mbm != null)
- {
- x.groupName = mbm?.groupName;
- x.name = !string.IsNullOrWhiteSpace(x.name) ? x.name : mbm?.name;
- x.nickname = mbm?.nickname;
- x.picture = mbm?.picture;
-
- }
- });
- return (returnTrains, yxtrain);
- }
- private static async Task<List<TeacherTrain>> GetStatisticsTeacher(List<TeacherTrain> trains, AreaSetting setting, Area area, CosmosClient client, List<Study> studies)
- {
- List<Task<TeacherTrain>> teachers = new List<Task<TeacherTrain>>();
- foreach (var train in trains)
- {
- teachers.Add(StatisticsTeacher(train, setting, area, client, studies)); //yield return await StatisticsTeacher( train, setting, area, client);
- }
- int pagesize = 50;
- if (teachers.Count <= pagesize)
- {
- await Task.WhenAll(teachers);
- }
- else
- {
- int pages = (teachers.Count + pagesize) / pagesize; //256是批量操作最大值,pages = (total + max -1) / max;
- for (int i = 0; i < pages; i++)
- {
- var lists = teachers.Skip((i) * pagesize).Take(pagesize).ToList();
- await Task.WhenAll(lists);
- }
- }
- return trains;
- }
- public static async Task<TeacherTrain> StatisticsTeacher(TeacherTrain train, AreaSetting setting, Area area, CosmosClient client, List<Study> studies)
- {
- string _school = train.school;
- string _tmdid = train.tmdid;
- // TeacherTrain teacher_train = null;
- List<Task<TeacherTrain>> teachers = new List<Task<TeacherTrain>>();
- if (train.update.Count > 0)
- {
- foreach (string property in train.update)
- {
- teachers.Add(DoProperty(train.update, property, setting, area, client, train, studies));
- }
- int pagesize = 50;
- if (teachers.Count <= pagesize)
- {
- await Task.WhenAll(teachers);
- }
- else
- {
- int pages = (teachers.Count + pagesize) / pagesize; //256是批量操作最大值,pages = (total + max -1) / max;
- for (int i = 0; i < pages; i++)
- {
- var lists = teachers.Skip((i) * pagesize).Take(pagesize).ToList();
- await Task.WhenAll(lists);
- }
- }
- }
- //每次都统计活动相关的数据。
- // train= await DoActivity(train, setting, area, client, _school, _tmdid);
- train.totalTime = train.onlineTime + train.classTime + train.currency.submitTime + train.offlineTime;
- if (train.totalTime >= setting.allTime)
- {
- //如果总学生超过50 且不是优秀则至少是合格。
- if (train.finalScore != 2)
- {
- train.finalScore = 1;
- }
- }
- // 50> 学时>0 是不合格
- else if (train.totalTime < setting.allTime && train.totalTime > 0)
- {
- train.finalScore = 0;
- }
- else
- {
- //学时<=0 则是为
- train.finalScore = -1;
- }
- await client.GetContainer(Constant.TEAMModelOS, "Teacher").UpsertItemAsync<TeacherTrain>(train, new PartitionKey($"TeacherTrain-{_school}"));
- return train;
- }
- private static async Task<TeacherTrain> DoProperty(HashSet<string> updateProperty, string property, AreaSetting setting, Area area, CosmosClient client, TeacherTrain train, List<Study> studies)
- {
- string _school = train.school;
- string _tmdid = train.tmdid;
- switch (property)
- {
- case TeacherAbility:
- train = await DoTeacherAbility(train, setting, area, client, _school, _tmdid);
- train.update.Remove(TeacherAbility);
- break;
- //课堂实录更新
- case TeacherClass:
- train = await DoTeacherClass(train, setting, area, client, _school, _tmdid);
- train.update.Remove(TeacherClass);
- break;
- //线下研修
- case OfflineRecord:
- train = await DoOfflineRecord(train, setting, area, client, _school, _tmdid, studies);
- train.update.Remove(OfflineRecord);
- break;
- //投票
- case TeacherVote:
- train = await DoTeacherVote(train, setting, area, client, _school, _tmdid);
- train.update.Remove(TeacherVote);
- break;
- //问卷
- case TeacherSurvey:
- train = await DoTeacherSurvey(train, setting, area, client, _school, _tmdid);
- train.update.Remove(TeacherSurvey);
- break;
- //作业
- //case TeacherHomework:
- // train = await DoTeacherHomework(train, setting, area, client, _school, _tmdid);
- // train.updateProperty.Remove(TeacherHomework);
- // break;
- //评测
- case TeacherExamLite:
- train = await DoTeacherExamLite(train, setting, area, client, _school, _tmdid);
- train.update.Remove(TeacherExamLite);
- break;
- default:
- train.update.Remove(property);
- break;
- }
- return train;
- }
- public static async Task<TeacherTrain> DoTeacherVote(TeacherTrain train, AreaSetting setting, Area area, CosmosClient client, string _school, string _tmdid)
- {
- int voteJoin = 0;
- int voteDone = 0;
- int voteAreaJoin = 0;
- int voteAreaDone = 0;
- //投票活动
- await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher")
- .GetItemQueryIterator<StuActivity>(queryText: $"select c.owner, c.taskStatus from c where c.type = 'Vote' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Activity-{_tmdid}") }))
- {
- if (!string.IsNullOrEmpty(item.owner))
- {
- if (item.owner.Equals("school"))
- {
- voteJoin += 1;
- if (item.taskStatus > 0)
- {
- voteDone += 1;
- }
- }
- else if (item.owner.Equals("area"))
- {
- voteAreaJoin += 1;
- if (item.taskStatus > 0)
- {
- voteAreaDone += 1;
- }
- }
- }
- }
- train.voteJoin = voteJoin;
- train.voteDone = voteDone;
- train.voteAreaJoin = voteAreaJoin;
- train.voteAreaDone = voteAreaDone;
- return train;
- }
- public static async Task<TeacherTrain> DoTeacherSurvey(TeacherTrain train, AreaSetting setting, Area area, CosmosClient client, string _school, string _tmdid)
- {
- //问卷调查
- int surveyJoin = 0;
- int surveyDone = 0;
- int surveyAreaJoin = 0;
- int surveyAreaDone = 0;
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher")
- .GetItemQueryIterator<StuActivity>(queryText: $"select c.owner, c.taskStatus from c where c.type = 'Survey' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Activity-{_tmdid}") }))
- {
- if (!string.IsNullOrEmpty(item.owner))
- {
- if (item.owner.Equals("school"))
- {
- surveyJoin += 1;
- if (item.taskStatus > 0)
- {
- surveyDone += 1;
- }
- }
- else if (item.owner.Equals("area"))
- {
- surveyAreaJoin += 1;
- if (item.taskStatus > 0)
- {
- surveyAreaDone += 1;
- }
- }
- }
- }
- train.surveyJoin = surveyJoin;
- train.surveyDone = surveyDone;
- train.surveyAreaJoin = surveyAreaJoin;
- train.surveyAreaDone = surveyAreaDone;
- return train;
- }
- public static async Task<TeacherTrain> DoTeacherExamLite(TeacherTrain train, AreaSetting setting, Area area, CosmosClient client, string _school, string _tmdid)
- {
- //问卷调查
- int examJoin = 0;
- int examDone = 0;
- int examAreaJoin = 0;
- int examAreaDone = 0;
- //评量检测
- await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher")
- .GetItemQueryIterator<StuActivity>(queryText: $"select c.owner, c.taskStatus from c where c.type = 'ExamLite' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Activity-{_tmdid}") }))
- {
- if (!string.IsNullOrEmpty(item.owner))
- {
- if (item.owner.Equals("school"))
- {
- examJoin += 1;
- if (item.taskStatus > 0)
- {
- examDone += 1;
- }
- }
- else if (item.owner.Equals("area"))
- {
- examAreaJoin += 1;
- if (item.taskStatus > 0)
- {
- examAreaDone += 1;
- }
- }
- }
- }
- train.examJoin = examJoin;
- train.examDone = examDone;
- train.examAreaJoin = examAreaJoin;
- train.examAreaDone = examAreaDone;
- return train;
- }
- /// <summary>
- /// 课堂实录更新
- /// </summary>
- /// <param name="train"></param>
- /// <param name="setting"></param>
- /// <param name="area"></param>
- /// <param name="client"></param>
- /// <param name="_school"></param>
- /// <param name="_tmdid"></param>
- /// <returns></returns>
- public static async Task<TeacherTrain> DoOfflineRecord(TeacherTrain train, AreaSetting setting, Area area, CosmosClient client, string _school, string _tmdid, List<Study> studies)
- {
- //owner: school area
- //线下 学校研修活动
- List<StuActivity> activities = new List<StuActivity>();
- await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher")
- .GetItemQueryIterator<StuActivity>(queryText: $"select value(c) from c where c.type = 'Study' and c.owner<>'area' and c.school='{_school}' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Activity-{_tmdid}") }))
- {
- activities.Add(item);
- }
- string insql = "";
- if (studies.IsEmpty())
- {
- studies = new List<Study>();
- if (activities.IsNotEmpty())
- {
- insql = $" where c.id in ({string.Join(",", activities.Select(o => $"'{o.id}'"))})";
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common")
- .GetItemQueryIterator<Study>(queryText: $"select value(c) from c {insql} and c.owner<>'area' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Study-{_school}") }))
- {
- studies.Add(item);
- }
- }
- }
- List<StudyRecord> studyRecords = new List<StudyRecord>();
- await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher")
- .GetItemQueryIterator<StudyRecord>(queryText: $"select value(c) from c {insql} ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"StudyRecord-{_tmdid}") }))
- {
- studyRecords.Add(item);
- }
- List<HomeworkRecord> homeworkRecords = new List<HomeworkRecord>();
- List<Study> workids = studies.FindAll(x => !string.IsNullOrEmpty(x.workId));
- bool haswork = false;
- List<string> workidSubmits = new List<string>();
- if (workids.IsNotEmpty())
- {
- string rcdsql = $" where c.id in ({string.Join(",", workids.Select(o => $"'{o.workId}'"))})";
- await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher")
- .GetItemQueryIterator<HomeworkRecord>(queryText: $"select value(c) from c {rcdsql} ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"HomeworkRecord-{_tmdid}") }))
- {
- var content = item.content.FindAll(x => x.prime);
- if (content.IsNotEmpty())
- {
- workidSubmits.Add(item.id);
- }
- homeworkRecords.Add(item);
- }
- //标记已经有需要提交作业的线下研修活动。则需要检查至少有一次的作业提交记录。否则不能获得学时。
- haswork = true;
- }
- //如果交了至少一份作业
- //一份作业都没有交
- //标记是否计算所有学时。
- bool getAll = false;
- if (haswork)
- {
- //如果有作业就需要检查是否至少交了一份作业。 如果交了一份,并且通过了,则可以计算全部。具体查看mark qweorrty
- getAll = false;
- }
- else
- {
- //如果没有作业,则计算全部学时。
- getAll = true;
- }
- activities.ForEach(item => {
- Study study = studies.Find(y => y.id.Equals(item.id) && !string.IsNullOrEmpty(y.workId));
- if (study != null)
- {
- StudyRecord studyRecord = studyRecords.Find(y => y.id.Equals(item.id));
- if (studyRecord != null && studyRecord.status > 0)
- {
- //mark qweorrty
- var submit = workidSubmits.Find(y => y.Equals(study.workId));
- if (submit != null)
- {
- getAll = true;
- }
- }
- }
- });
- List<OfflineRecord> offlines = new List<OfflineRecord>();
- activities.ForEach(item =>
- {
- Study study = studies.Find(y => y.id.Equals(item.id));
- if (study != null)
- {
- StudyRecord studyRecord = studyRecords.Find(y => y.id.Equals(item.id));
- OfflineRecord record = new OfflineRecord
- {
- id = item.id,
- name = item.name,
- done = item.taskStatus,
- owner = item.owner,
- sethour = study.hour
- };
- bool workOk = false;
- if (!string.IsNullOrEmpty(study.workId))
- {
- HomeworkRecord homeworkRecord = homeworkRecords.Find(y => y.id.Equals(study.workId));
- record.other = homeworkRecord?.content;
- Attachment attachment = homeworkRecord != null ? homeworkRecord.content.Find(x => x.prime) : null;
- record.haswork = 1;
- if (null != attachment)
- {
- record.url = attachment.url;
- record.upload = 1;
- record.hash = attachment.hash;
- record.size = attachment.size;
- workOk = true;
- }
- }
- if (studyRecord != null)
- {
- if (getAll)
- {
- record.hour = studyRecord.status == 1 ? study.hour : 0;
- record.score = studyRecord.status;
- if (record.score >= 0)
- {
- record.done = 1;
- }
- else
- {
- record.score = -1;
- }
- }
- else
- {
- if (workOk && !string.IsNullOrEmpty(study.workId))
- {
- record.hour = studyRecord.status == 1 ? study.hour : 0;
- record.score = studyRecord.status;
- if (record.score >= 0)
- {
- record.done = 1;
- }
- else
- {
- record.score = -1;
- }
- }
- else if (!workOk && !string.IsNullOrEmpty(study.workId))
- {
- //没有交任何作业,即使通过,也不会获得学时。
- record.hour = 0;
- record.score = studyRecord.status;
- }
- else
- {
- record.hour = studyRecord.status == 1 ? study.hour : 0;
- record.score = studyRecord.status;
- if (record.score >= 0)
- {
- record.done = 1;
- }
- else
- {
- record.score = -1;
- }
- }
- }
- }
- offlines.Add(record);
- }
- });
- //标记已经有需要提交作业的线下研修活动。则需要检查至少有一次的作业提交记录。否则不能获得学时。
- int sum = offlines.Select(x => x.hour).Sum();
- //if (haswork)
- //{
- // var workd= homeworkRecords.Where(z=>z.content.IsNotEmpty()).SelectMany(x => x.content).Where(y => y.prime);
- // if (workd != null && workd.Count() > 0) {
- // sum = offlines.Select(x => x.hour).Sum();
- // }
- //}
- //else
- //{
- // sum = offlines.Select(x => x.hour).Sum();
- //}
- //有作业,且没有交任何作业。
- if (workidSubmits.IsEmpty() && haswork)
- {
- train.offlineTime = 0;
- }
- else
- {
- train.offlineTime = sum > setting.offlineTime ? setting.offlineTime : sum;
- }
- train.offlineRecords = offlines;
- return train;
- }
- /// <summary>
- /// 课堂实录更新
- /// </summary>
- /// <param name="train"></param>
- /// <param name="setting"></param>
- /// <param name="area"></param>
- /// <param name="client"></param>
- /// <param name="_school"></param>
- /// <param name="_tmdid"></param>
- /// <returns></returns>
- public static async Task<TeacherTrain> DoTeacherClass(TeacherTrain train, AreaSetting setting, Area area, CosmosClient client, string _school, string _tmdid)
- {
- string code = $"ClassVideo-{_school}";
- ClassVideo classVideo = null;
- try
- {
- classVideo = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<ClassVideo>($"{_tmdid}", new PartitionKey(code));
- }
- catch (Exception ex)
- {
- classVideo = null;
- }
- if (classVideo != null && classVideo.files.IsNotEmpty())
- {
- //2021.11.17 15:05,与J哥确认,取课堂实录第一个。前端也只show第一个视频。
- var files = classVideo.files[0];
- if (files.score > 0)
- {
- train.classTime = setting.classTime;
- }
- else
- {
- train.classTime = 0;
- }
- train.teacherClasses = new List<TeacherClass> { new Models.TeacherClass { url = files.url, score = files.score, hash = files.hash, name = files.name, size = files.size } };
- }
- else
- {
- train.classTime = 0;
- }
- return train;
- }
- public static async Task<TeacherTrain> DoTeacherAbility(TeacherTrain train, AreaSetting setting, Area area, CosmosClient client, string _school, string _tmdid)
- {
- //视频播放
- List<string> abilityIds = new List<string>();
- TeacherFile file = null;
- try
- {
- file = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<TeacherFile>(_tmdid, new PartitionKey($"TeacherFile-{_school}"));
- }
- catch (CosmosException)
- {
- file = new TeacherFile
- {
- id = _tmdid,
- code = $"TeacherFile-{_school}",
- pk = "TeacherFile",
- ttl = -1,
- };
- await client.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<TeacherFile>(file, new PartitionKey($"TeacherFile-{_school}"));
- }
- List<AbilitySub> abilitySubs = new List<AbilitySub>();
- //认证材料
- await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher")
- .GetItemQueryIterator<AbilitySub>(queryText: $"select value(c) from c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"AbilitySub-{_school}-{_tmdid}") }))
- {
- abilitySubs.Add(item);
- }
- List<Ability> abilities = new List<Ability>();
- string insql = "";
- if (abilitySubs.IsNotEmpty())
- {
- insql = $" where c.id in ({string.Join(",", abilitySubs.Select(o => $"'{o.id}'"))})";
- }
- await foreach (var item in client.GetContainer("TEAMModelOS", "Normal")
- .GetItemQueryIterator<Ability>(queryText: $"select c.comid, c.id,c.name,c.currency,c.no,c.dimension,c.hour,c.stds,c.abilityCount from c {insql} ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Ability-{area.standard}") }))
- {
- abilities.Add(item);
- }
- List<Debate> debates = new List<Debate>();
- if (abilities.IsNotEmpty())
- {
- await foreach (var item in client.GetContainer("TEAMModelOS", "School")
- .GetItemQueryIterator<Debate>(queryText: $"select distinct value(c) from c join b in c.replies where b.tmdid='{_tmdid}'and c.source='uploadscore' and c.comid in ({string.Join(",", abilities.Select(o => $"'{o.comid}'"))})",
- requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Debate-{_school}") }))
- {
- debates.Add(item);
- }
- }
- Currency currency = new Currency();
- // Currency currencyAll = new Currency();
- abilitySubs.ForEach(item => {
- int currencyInt = item.from == 1 ? 1 : 0;
- Ability ability = abilities.Find(x => x.id.Equals(item.id));
- if (ability != null)
- {
- if (ability != null)
- {
- currencyInt = item.from == 0 ? ability.currency : 1;
- }
- else
- {
- currencyInt = 0;
- }
- if (item.uploads.IsNotEmpty())
- {
- if (currencyInt == 1)
- {
- currency.uploadDone += item.uploads.Count;
- }
- // currencyAll.uploadDone += item.uploads.Count;
- }
- //通过能力点自测
- if (item.exerciseScore > 0)
- {
- if (currencyInt == 1)
- {
- // 与J哥 ,郭杰确认。只计算通过能力点自测就能获得的成长值。 并取消已学能力点 learnAbility
- currency.exerciseAbility += ability.abilityCount;
- //并且完全看完视频和文档。
- if (item.allDone)
- {
- currency.learnAbility += 1;
- }
- }
- //并且完全看完视频和文档。
- //if (item.allDone)
- //{
- // currencyAll.learnAbility += 1;
- //}
- //currencyAll.exerciseAbility += ability.abilityCount;
- }
- List<TeacherHprecord> hprecords = new List<TeacherHprecord>();
- List<Debate> debateOrthers = debates.FindAll(x => x.comid.Equals(ability.comid) && x.replies.IsNotEmpty());
- int debateOrther = -1;
- List<string> replyIds = new List<string>();
- if (debateOrthers.IsNotEmpty())
- {
- debateOrther = debateOrthers.Count;
- var replies = debateOrthers.SelectMany(x => x.replies).Where(z => z.tmdid.Equals(_tmdid));
- if (replies != null && replies.Count() > 0)
- {
- replyIds = replies.Select(x => x.id).ToList();
- }
- }
- TeacherAbility teacherAbility = new Models.TeacherAbility
- {
- replyIds = replyIds,
- debateOrther = debateOrther,
- id = ability.id,
- currency = currencyInt,
- no = ability.no,
- name = ability.name,
- dimension = ability.dimension,
- zpscore = item.self == 0 ? 1 : item.self,
- hprecord = hprecords,
- uploadHas = item.uploads.Count
- };
- if (file != null)
- {
- double view = 0;
- file.fileRecords.ForEach(record => {
- var abilityVideo = record.files.FindAll(x => x.abilityId.Equals(item.id));
- if (abilityVideo.IsNotEmpty())
- {
- view += record.view;
- }
- });
- //能力点学时限制
- int limit = ability.hour * setting.lessonMinutes;
- //如果超过 8* 45分钟学时,则直接赋值360(limit)分钟。
- view = view / 60;
- view = view > limit ? limit : view;
- teacherAbility.videoTime = (int)view;
- teacherAbility.limitTime = ability.hour;
- teacherAbility.onlineTime = setting.lessonMinutes != 0 ? (int)(view / setting.lessonMinutes) : 0;
- }
- if (item.otherScore.IsNotEmpty())
- {
- var schoolScore = item.otherScore.Where(x => x.roleType.Equals("school")).FirstOrDefault();
- if (schoolScore != null && schoolScore.score >= 0)
- {
- teacherAbility.xzscore = schoolScore.score;
- teacherAbility.xztime = schoolScore.time;
- teacherAbility.xztmdid = schoolScore.tmdid;
- teacherAbility.xztmdname = schoolScore.tmdname;
- }
- var hprecord = item.otherScore.FindAll(x => x.roleType.Equals("member")).Select(y => new TeacherHprecord { tmdid = y.tmdid, tmdname = y.tmdname, score = y.score });
- if (hprecord != null)
- {
- var no = hprecord.Where(x => x.score == 0) != null ? hprecord.Where(x => x.score == 0).Count() : 0;
- var hg = hprecord.Where(x => x.score == 1) != null ? hprecord.Where(x => x.score == 1).Count() : 0;
- var yx = hprecord.Where(x => x.score == 2) != null ? hprecord.Where(x => x.score == 2).Count() : 0;
- if (no == hg && hg == yx && no == 0)
- {
- //未评分 合格,优秀都是0 则未评分
- teacherAbility.hpscore = -1;
- }
- else if (no == hg && hg == yx && no != 0)
- {
- //未评分,合格,优秀不为0 且一样,按优秀算
- teacherAbility.hpscore = 2;
- }
- else
- {
- bool ok = false;
- List<int> arr = new List<int>() { yx, hg, no };
- int max = arr.Max();
- //有优秀按优秀算
- if (max == yx && !ok)
- {
- teacherAbility.hpscore = 2;
- ok = true;
- }
- //最高评分是合格,按合格算
- if (max == hg && !ok)
- {
- teacherAbility.hpscore = 1;
- ok = true;
- }
- //最高评分是未评分则按未评分算
- if (max == no && !ok)
- {
- teacherAbility.hpscore = 0;
- ok = true;
- }
- }
- teacherAbility.hprecord.AddRange(hprecord);
- }
- }
- if (currencyInt == 1)
- {
- currency.subCount += 1;
- currency.uploadTotal += ability.stds.FindAll(x => x.task.IsNotEmpty()).Select(y => y.task).Count();
- currency.teacherAilities.Add(teacherAbility);
- }
- // currencyAll.subCount += 1;
- // currencyAll.uploadTotal += ability.stds.FindAll(x => x.task.IsNotEmpty()).Select(y => y.task).Count();
- // currencyAll.teacherAilities.Add(teacherAbility);
- }
- });
- train.currency = currency;
- // train.currencyAll = currencyAll;
- train.currency.videoTime = train.currency.teacherAilities.Select(x => x.videoTime).Sum();
- // train.currencyAll.videoTime = train.currencyAll.teacherAilities.Select(x => x.videoTime).Sum();
- //如果总分钟数超过20学时,则直接复制20学时。
- var videoTime = setting.lessonMinutes != 0 ? (int)(train.currency.videoTime / setting.lessonMinutes) : 0;
- train.onlineTime = videoTime > setting.onlineTime ? setting.onlineTime : videoTime;
- var bhg = train.currency.teacherAilities.FindAll(x => x.xzscore > 0);
- //由于有教师在省平台勾选太多能力点,暂时获得xzscore 数量大于三个的,也能获得学时
- int limitAbility = 3;
- if (setting.limitAbility != -1) {
- limitAbility=setting.limitAbility;
- }
- if (bhg.IsNotEmpty() && (bhg.Count == train.currency.subCount|| bhg.Count>= limitAbility))
- {
- ///要全部合格才能获得学时。
- train.currency.submitTime = setting.submitTime;
- // train.currencyAll.submitTime = setting.submitTime;
- }
- return train;
- }
- }
- }
|