Prechádzať zdrojové kódy

update 自动补学时的检查逻辑。

CrazyIter_Bin 3 rokov pred
rodič
commit
91bccf7567

+ 3 - 3
TEAMModelOS.FunctionV4/ServiceBus/ActiveTaskTopic.cs

@@ -1394,8 +1394,8 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                         var messageChange = new ServiceBusMessage(new   { delete_id =lessonId, tmdid =tmdid,scope=scope,opt="delete",school=school}.ToJsonString());
                         messageChange.ApplicationProperties.Add("name", "LessonRecordEvent");
                         await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageChange);
-                        await _dingDing.SendBotMsg($"课例因【{lessonRecord.name}】,【{lessonRecord.id}】时间到期,即将被自动删除,到期时间:" +
-                            $"{lessonRecord.expire}\n{lessonRecord.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
+                        await _dingDing.SendBotMsg($"课例因【{lessonRecord.name}】,课例ID:【{lessonRecord.id}】时间到期,即将被自动删除,到期时间:" +
+                            $"{lessonRecord.expire}\n{lessonRecord.ToJsonString()}", GroupNames.成都开发測試群組);
                     }
                 }
                 string biz = "expire";
@@ -1648,7 +1648,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
                         }
                         catch (CosmosException ex)
                         {
-                            await _dingDing.SendBotMsg($"OS,{ Environment.GetEnvironmentVariable("Option:Location")},CourseServiceBus -CosmosDB异常\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
+                            //await _dingDing.SendBotMsg($"OS,{ Environment.GetEnvironmentVariable("Option:Location")},CourseServiceBus -CosmosDB异常\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
                         }
                     }
                     foreach (var tmd in delTmdidsCls)

+ 118 - 51
TEAMModelOS/Controllers/XTest/TestController.cs

@@ -758,13 +758,14 @@ namespace TEAMModelOS.Controllers
             await table.SaveOrUpdateAll(teachersUp);
             return Ok();
         }
-        [HttpPost("get-teacher-ability-files")]
+        [HttpPost("fix-jinniupujiang-teacher-videotime")]
         public async Task<IActionResult> GetScteacher(JsonElement json) {
             if (!json.TryGetProperty("areaId", out JsonElement _areaId)) { return BadRequest(); }
             Area area= await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).ReadItemAsync<Area>($"{_areaId}", new PartitionKey("Base-Area"));
+            AreaSetting  setting = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).ReadItemAsync<AreaSetting>($"{_areaId}", new PartitionKey("AreaSetting"));
             List<string> teachers = new List<string>();
             //获取这个区的教师
-            string schoolSql = "SELECT value  c.id FROM c join a in c.schools where a.areaId='870a5a6b-1ab3-461a-bdeb-baec19780ddb' and c.code='Base' ";
+            string schoolSql = $"SELECT value  c.id FROM c join a in c.schools where a.areaId='{_areaId}' and c.code='Base' ";
             await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
                 .GetItemQueryIterator<string>(schoolSql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
             {
@@ -776,7 +777,7 @@ namespace TEAMModelOS.Controllers
             await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
                 .GetItemQueryIterator<TeacherTrain>(tr, requestOptions: new QueryRequestOptions {  }))
             {
-                if (!item.tmdid.Equals("1528783259")) {
+                if (!item.tmdid.Equals("1528783259") || !item.tmdid.Equals("1530606136")  ) {
                     teacherTrains.Add(item);
                 }
             }
@@ -788,53 +789,68 @@ namespace TEAMModelOS.Controllers
             {
                 nodeIdsDB.Add(y);
             }
+            List<AbilitySub> abilitySubs = new List<AbilitySub>();
+            List< TeacherVideoTime > teacherVideoTimes= new List<TeacherVideoTime>();
+            string ids = teacherTrains.Select(x => x.id).ToJsonString();
+            string sqls = $" select value(c) from c  where   c.code='AbilityTask-{area.standard}'";
+            List<AbilityTask> abilityTasks = new List<AbilityTask>();
+            Dictionary<string, RecordFileAbility> valuePairs = new Dictionary<string, RecordFileAbility>();
+            await foreach (var y in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).GetItemQueryIterator<AbilityTask>
+                    (sqls, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilityTask-{area.standard}") }))
+            {
+                abilityTasks.Add(y);
+            }
             foreach (var item in teacherTrains)
             {
                 List<TeacherAbility> teacherAbility = new List<TeacherAbility>();
                 if (item.currency.teacherAilities.Count() > 3)
                 {
                     //如果选择了大于三个能力点的教师,则优先获取上传了认证材料的的能力点,
-                    var uploadHas=  item.currency.teacherAilities.FindAll(x => x.uploadHas == 1);
+                    var uploadHas=  item.currency.teacherAilities.FindAll(x => x.uploadHas == 1  && x.videoTime<300);
                     if (uploadHas.Any()) {
                         teacherAbility.AddRange(uploadHas);
                     }
-                    // 如果仍然未满足数量。则再去获取 没有上传认证材料,但是又有学习时间长的能力点。
-                    var hasVideoTime = item.currency.teacherAilities.FindAll(x => x.uploadHas != 1);
+
+                    if (teacherAbility.Count < 3) {
+                        // 如果仍然未满足数量。则再去获取 没有上传认证材料,但是又有学习时间长的能力点。
+                        var hasVideoTime = item.currency.teacherAilities.FindAll(x => x.uploadHas != 1 && x.videoTime < 300).OrderByDescending(o=>o.videoTime);
+                        var disCount = 3 - teacherAbility.Count;
+                        teacherAbility.AddRange(hasVideoTime.Take(disCount));
+                    }
                 }
                 else {
-                    teacherAbility.AddRange(item.currency.teacherAilities);
+                    teacherAbility.AddRange(item.currency.teacherAilities.Where(ab=>ab.videoTime<300));
                 }
-
                 TeacherFile teacherFile = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<TeacherFile>(item.id, new PartitionKey($"TeacherFile-{item.code.Replace("TeacherTrain-", "")}"));
-                foreach (var x in item.currency.teacherAilities)
+                foreach (var ability in teacherAbility)
                 {
-                    //某个能力点大于300
-                    if (x.videoTime >= 300) {
-                        continue;
-                    }
-                    string sqls = $" select value(c) from c  where c.abilityId='{x.id}' and c.code='AbilityTask-{area.standard}'";
-                    List<AbilityTask> abilityTasks = new List<AbilityTask>();
-                    Dictionary<string, RecordFileAbility> valuePairs = new Dictionary<string, RecordFileAbility>();
-                    await foreach (var y in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).GetItemQueryIterator<AbilityTask>
-                            (sqls, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilityTask-{area.standard}") }))
-                    {
-                        abilityTasks.Add(y);
-                    }
+                    TeacherVideoTime teacherVideoTime = new TeacherVideoTime { code= item.code.Replace("TeacherTrain-", ""), id = item.id, abilityId = ability.id, no = ability.no, train_time = ability.videoTime };
+                    double fileview = 0;
+                    var filerecord = teacherFile.fileRecords.FindAll(x => x.files.Where(y => y.abilityId.Equals(ability.id)).Count() > 0);
+                    filerecord.ForEach(x => {
+                        var file = x.files.FindAll(y => y.abilityId.Equals($"{ability.id}"));
+                        if (file.IsNotEmpty())
+                        {
+                            fileview += x.view;
+                        }
+                    });
+                    double fminut = fileview / 60;
+                    teacherVideoTime.files_time = fminut;
+                    var tech = abilityTasks.FindAll(x => x.abilityId.Equals(ability.id));
                     //   double limit = 0;
-                    abilityTasks.ForEach(x =>
+                    tech.ForEach(task =>
                     {
-                        x.children.ForEach(y =>
+                        task.children.ForEach(y =>
                         {
                             y.rnodes.ForEach(r =>
                             {
-
                                 if (valuePairs.ContainsKey(r.hash))
                                 {
                                     valuePairs.TryGetValue(r.hash, out var value);
-                                    var ablt = value.fileAbilities.Find(z => z.abilityId.Equals(x.abilityId) && z.taskId.Equals(x.id) && z.nodeId.Equals(y.id));
+                                    var ablt = value.fileAbilities.Find(z => z.abilityId.Equals(task.abilityId) && z.taskId.Equals(task.id) && z.nodeId.Equals(y.id));
                                     if (ablt == null)
                                     {
-                                        value.fileAbilities.Add(new FileAbility { url = r.link, abilityId = x.abilityId, taskId = x.id, nodeId = y.id });
+                                        value.fileAbilities.Add(new FileAbility { url = r.link, abilityId = task.abilityId, taskId = task.id, nodeId = y.id });
                                         // limit = limit + r.duration;
                                     }
                                 }
@@ -844,51 +860,102 @@ namespace TEAMModelOS.Controllers
                                     {
                                         fileRecord =
                                         new FileRecord { hash = r.hash, size = r.size.Value, duration = r.duration, view = (int)r.duration, type = r.type, done = true },
-                                        fileAbilities = new List<FileAbility> { new FileAbility { url = r.link, abilityId = x.abilityId, taskId = x.id, nodeId = y.id } }
+                                        fileAbilities = new List<FileAbility> { new FileAbility { url = r.link, abilityId = task.abilityId, taskId = task.id, nodeId = y.id } }
                                     });
                                     // limit = limit + r.duration;
                                 }
                             });
                         });
                     });
-
+                    HashSet<string> childIds = new HashSet<string>();
                     foreach (var ps in valuePairs)
                     {
-                        var fils = teacherFile.fileRecords.Find(x => x.hash.Equals(ps.Key));
-                        if (fils != null)
-                        {
-                            ps.Value.fileAbilities.ForEach(x =>
-                            {
-                                var a = fils.files.Find(z => z.nodeId.Equals(x.nodeId) && z.abilityId.Equals(x.abilityId));
-                                if (a == null)
+                        HashSet<string> abilityIds = teacherFile.fileRecords.SelectMany(x => x.files).Select(x => x.abilityId).Where(abid=>abid.Equals(ability.id)).ToHashSet();
+                        double view = 0;
+                        foreach (var abid in abilityIds) {
+                            var record = teacherFile.fileRecords.FindAll(x => x.files.Where(y => y.abilityId.Equals(abid)).Count() > 0);
+                            record.ForEach(x => {
+                                var file = x.files.FindAll(y => y.abilityId.Equals($"{abid}"));
+                                if (file.IsNotEmpty())
                                 {
-                                    fils.files.Add(new FileAbility { url = x.url, abilityId = x.abilityId, taskId = x.taskId, nodeId = x.nodeId });
+                                    view += x.view;
                                 }
                             });
                         }
-                        else
+                        double minut = view / 60;
+                        teacherVideoTime.after_time= minut;
+                        if (minut < 300)
                         {
-                            teacherFile.fileRecords.Add(new FileRecord
+                            var fils = teacherFile.fileRecords.Find(x => x.hash.Equals(ps.Key));
+                            if (fils != null)
                             {
-                                hash = ps.Value.fileRecord.hash,
-                                size = ps.Value.fileRecord.size,
-                                duration = ps.Value.fileRecord.duration,
-                                view = (int)ps.Value.fileRecord.view,
-                                type = ps.Value.fileRecord.type,
-                                done = true,
-                                files = ps.Value.fileAbilities
-                            });
+                                ps.Value.fileAbilities.ForEach(x =>
+                                {
+                                    var a = fils.files.Find(z => z.nodeId.Equals(x.nodeId) && z.abilityId.Equals(x.abilityId));
+                                    if (a == null)
+                                    {
+                                        childIds.Add(x.nodeId);
+                                        fils.files.Add(new FileAbility { url = x.url, abilityId = x.abilityId, taskId = x.taskId, nodeId = x.nodeId });
+                                    }
+                                });
+                            }
+                            else
+                            {
+                                ps.Value.fileAbilities.ForEach(x =>
+                                {
+                                    childIds.Add(x.nodeId);
+                                });
+                                teacherFile.fileRecords.Add(new FileRecord
+                                {
+                                    hash = ps.Value.fileRecord.hash,
+                                    size = ps.Value.fileRecord.size,
+                                    duration = ps.Value.fileRecord.duration,
+                                    view = (int)ps.Value.fileRecord.view,
+                                    type = ps.Value.fileRecord.type,
+                                    done = true,
+                                    files = ps.Value.fileAbilities
+                                });
+                            }
+                        }
+                        else { 
+                            break;
                         }
                     }
+                    if (childIds.Any()) {
+                       string code = teacherFile.code.Replace("TeacherFile-", "");
+                        if (!string.IsNullOrWhiteSpace(code)) {
+                            try {
+                                AbilitySub abilitySub = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<AbilitySub>(ability.id, new PartitionKey($"AbilitySub-{code}-{teacherFile.id}"));
+                                var taskIds= abilitySub.taskRcds.Select(x => x.id);
+                                var notin= childIds.Except(taskIds);
+                                if (notin.Any()) {
+                                    abilitySub.taskRcds.AddRange(notin.Select(x => new AbilityTaskRcd { id=x,done=true}));
+                                    abilitySubs.Add(abilitySub);
+                                }
+                            } catch (Exception ex) {
+                            }
+                        }
+                    }
+                    teacherVideoTimes.Add(teacherVideoTime);
                 }
-                teacherFile = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync<TeacherFile>(teacherFile, teacherFile.id, new PartitionKey(teacherFile.code));
-                item.update.Add(StatisticsService.TeacherAbility);
-                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync<TeacherTrain>(item, item.id, new PartitionKey(item.code));
+               // teacherFile = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync<TeacherFile>(teacherFile, teacherFile.id, new PartitionKey(teacherFile.code));
+               // item.update.Add(StatisticsService.TeacherAbility);
+               // await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync<TeacherTrain>(item, item.id, new PartitionKey(item.code));
             }
-            return Ok(new {});
-        }
 
+            var data =  teacherVideoTimes.GroupBy(x => x.code).Select(x=>new { x.Key,count= x.ToList().Count,list =x.ToList()}).OrderByDescending(x=>x.count);
+            return Ok(new { data, abilitySubs });
+        }
 
+        public class TeacherVideoTime{
+            public string code { get; set; }
+            public string id { get; set; }
+            public string abilityId { get; set; }
+            public string no { get; set; }
+            public double train_time { get; set; }
+            public double files_time { get; set; }
+            public double after_time { get; set; }
+        }
 
         [HttpPost("get-teacher-video")]
         public async Task<IActionResult> GetScteacherClassVideo(JsonElement json)

+ 1 - 0
TEAMModelOS/Properties/launchSettings.json

@@ -22,6 +22,7 @@
       "commandName": "Project",
       "launchBrowser": true,
       //"launchUrl": "login",
+      //"applicationUrl": "http://kong.sso.com:5000",
       "applicationUrl": "https://localhost:5001;http://localhost:5000",
       "environmentVariables": {
         "ASPNETCORE_ENVIRONMENT": "Development"