1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084 |
- using Microsoft.Azure.Cosmos;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.Configuration;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Models;
- 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 class TeacherTrainChangeMsg {
- public string areaId { get; set; }
- public List<TeacherTrainChangeMsgSchoolTeachers> schools { get; set; } = new List<TeacherTrainChangeMsgSchoolTeachers>();
- }
- public class TeacherTrainChangeMsgSchoolTeachers {
- public string school { get; set; }
- public List<string> teachers { get; set; } = new List<string>();
- }
- 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").GetItemQueryIteratorSql<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").GetItemQueryIteratorSql<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")
- // .GetItemQueryIteratorSql<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, List<TeacherTrain> updateTeacherTrains)> 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, null) ;
- }
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher")
- .GetItemQueryIteratorSql<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> updateTeacherTrains = new List<TeacherTrain>();
- List<TeacherTrain> returnTrains = new List<TeacherTrain>();
- if (update.IsNotEmpty())
- {
- updateTeacherTrains.AddRange(update);
- }
- if (unStatistics != null)
- {
- foreach (string x in unStatistics)
- {
- var member = members.Find(y => y.id.Equals(x));
- updateTeacherTrains.Add(new TeacherTrain
- {
- pk = "TeacherTrain",
- id = x,
- code = $"TeacherTrain-{school}",
- tmdid = x,
- nickname = member.nickname,
-
- name = member.name,
- picture = member.picture,
- school = school,
- groupName=member.groupName,
- update = new HashSet<string> { TeacherAbility, TeacherClass, OfflineRecord }
- });
- }
- }
- //List<Study> studies = new List<Study>();
- //await foreach (var item in client.GetContainer("TEAMModelOS", "Common")
- // .GetItemQueryIteratorSql<Study>(queryText: $"select value(c) from c where c.owner<>'area' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Study-{school}") }))
- //{
- // studies.Add(item);
- //}
-
- returnTrains .AddRange(updateTeacherTrains) ;
- // 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.name = !string.IsNullOrWhiteSpace(x.name) ? x.name : mbm?.name;
- x.nickname = mbm?.nickname;
- x.picture = mbm?.picture;
- x.groupName = mbm?.groupName;
- }
- });
- return (returnTrains, yxtrain, updateTeacherTrains);
- }
- 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")
- .GetItemQueryIteratorSql<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,
- groupName = member.groupName,
- update = new HashSet<string> { TeacherAbility, TeacherClass, OfflineRecord }
- });
- }
- }
- List<Study> studies = new List<Study>();
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common")
- .GetItemQueryIteratorSql<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);
- }
- public 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 = 20;
- 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 = 20;
- 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")
- .GetItemQueryIteratorSql<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")
- .GetItemQueryIteratorSql<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")
- .GetItemQueryIteratorSql<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")
- .GetItemQueryIteratorSql<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")
- .GetItemQueryIteratorSql<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")
- .GetItemQueryIteratorSql<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")
- .GetItemQueryIteratorSql<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?.content.Find(x => x.prime);
- 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")
- .GetItemQueryIteratorSql<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")
- .GetItemQueryIteratorSql<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")
- .GetItemQueryIteratorSql<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;
- }
- }
- }
|