CrazyIter_Bin 2 éve
szülő
commit
df017256b9

+ 148 - 98
TEAMModelOS.FunctionV4/HttpTrigger/IESHttpTrigger.cs

@@ -83,127 +83,177 @@ namespace TEAMModelOS.FunctionV4.HttpTrigger
         [Function("area-artsetting-change")]
         public async Task<HttpResponseData> AreaArtSettingChange([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestData req) {
             var response = req.CreateResponse(HttpStatusCode.OK);
-            string data = await new StreamReader(req.Body).ReadToEndAsync();
-            var json = JsonDocument.Parse(data).RootElement;
-            json.TryGetProperty("areaId", out JsonElement _areaId);
-            string schoolSQL = $"select value c from c where c.areaId='{_areaId}'";
-            List<School> schools = new List<School>();
-            await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School)
-                           .GetItemQueryIterator<School>(queryText: schoolSQL, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Base") }))
-            {
-                schools.Add(item);
-            }           
-            ArtSetting artSetting= await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).ReadItemAsync<ArtSetting>($"{_areaId}", new PartitionKey("ArtSetting"));
-            foreach (var school in schools) {
-                List<Period> periods = new List<Period>();
-                var hastype = school.period.Where(p => p.type.IsNotEmpty());
-                if (hastype.Any()) {
-                    periods.AddRange(hastype);
-                }
-                var nottype = school.period.Where(p => p.type.IsEmpty());
-                if (nottype.Any()) {
-                    foreach (var type in nottype) { 
-                        
-                    }
+            try {
+                string data = await new StreamReader(req.Body).ReadToEndAsync();
+                var json = JsonDocument.Parse(data).RootElement;
+                json.TryGetProperty("areaId", out JsonElement _areaId);
+                string schoolSQL = $"select value c from c where c.areaId='{_areaId}'";
+                List<School> schools = new List<School>();
+                await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School)
+                               .GetItemQueryIterator<School>(queryText: schoolSQL, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Base") }))
+                {
+                    schools.Add(item);
                 }
-                foreach (var period in periods)
+                ArtSetting artSetting = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).ReadItemAsync<ArtSetting>($"{_areaId}", new PartitionKey("ArtSetting"));
+                foreach (var school in schools)
                 {
-                    var dimension = artSetting.dimensions.FindAll(x => x.type.Intersect(period.type).Any());
-                    var bindIds = period.subjects.Where(s => !string.IsNullOrWhiteSpace(s.bindId)).Select(x => x.bindId);
-                    //该学段未同步学科的。
-                    var unBindIds = dimension.Where(z => !string.IsNullOrWhiteSpace(z.subjectBind)).Select(x => x.subjectBind).ToHashSet().Except(bindIds);
-                    if (unBindIds.Any())
+                    List<Period> periods = new List<Period>();
+                    var hastype_period = school.period.Where(p => p.type.IsNotEmpty());
+                    if (hastype_period.Any())
                     {
-                        //尝试寻找同名学科且没有设置bindId的
-                        foreach (var unBindId in unBindIds)
+                        periods.AddRange(hastype_period);
+                    }
+                    var nottype_period = school.period.Where(p => p.type.IsEmpty());
+                    if (nottype_period.Any())
+                    {
+                        foreach (var period in nottype_period)
                         {
-                            var subjects = artSetting.dimensions.FindAll(d => !string.IsNullOrWhiteSpace(d.subjectBind) && !string.IsNullOrWhiteSpace(d.subject) && d.subjectBind.Equals(unBindId))?.Select(m => m.subject);
-                            if (subjects != null)
+                            if (period.name.Contains("小学"))
+                            {
+                                period.type.Add("primary");
+                            }
+                            if (period.name.Contains("初中"))
+                            {
+                                period.type.Add("junior");
+                            }
+                            if (period.name.Contains("高中"))
+                            {
+                                period.type.Add("senior");
+                            }
+                            if (period.type.IsEmpty() && school.period.Count == 1)
                             {
-                                foreach (var subject in subjects)
+                                if (school.name.Contains("小学"))
                                 {
-                                    //获取同名学科,且没绑定的
-                                    var sub = period.subjects.FindAll(sub => sub.name.Equals(subject) && string.IsNullOrWhiteSpace(sub.bindId));
-                                    if (sub.IsNotEmpty())
-                                    {
-                                        sub[0].bindId = unBindId;
-                                    }
-                                    else
-                                    {
-                                        period.subjects.Add(new Subject { id = Guid.NewGuid().ToString(), name = subject, bindId = unBindId, type = 1 });
-
-                                    }
-                                    break;
+                                    period.type.Add("primary");
+                                }
+                                if (school.name.Contains("初中"))
+                                {
+                                    period.type.Add("junior");
+                                }
+                                if (school.name.Contains("高中"))
+                                {
+                                    period.type.Add("senior");
                                 }
                             }
+                            if (period.type.IsNotEmpty())
+                            {
+                                periods.Add(period);
+                            }
                         }
                     }
-                    var period_subjects = period.subjects.Where(s => !string.IsNullOrWhiteSpace(s.bindId));
-                    foreach (var subject in period_subjects)
+                    foreach (var period in periods)
                     {
-                       var dim= dimension.Where(x => x.subjectBind.Equals(subject.bindId));
-                        if (dim.Any()) {
-                            Knowledge old = null;
-                            string sql = $"select value(c) from c where c.periodId = '{period.id}'";
-                            string pk = $"Knowledge-{school.id}-{subject.id}";
-                            await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").
-                                GetItemQueryIterator<Knowledge>(queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey(pk) }))
-                            {
-                                old = item;
-                                break;
-                            }
-                           
-                            //同步知识块。
-                            
-                            if (old != null)
+                        var dimension = artSetting.dimensions.FindAll(x => x.type.Intersect(period.type).Any());
+                        var bindIds = period.subjects.Where(s => !string.IsNullOrWhiteSpace(s.bindId)).Select(x => x.bindId);
+                        //该学段未同步学科的。
+                        var unBindIds = dimension.Where(z => !string.IsNullOrWhiteSpace(z.subjectBind)).Select(x => x.subjectBind).ToHashSet().Except(bindIds);
+                        if (unBindIds.Any())
+                        {
+                            //尝试寻找同名学科且没有设置bindId的
+                            foreach (var unBindId in unBindIds)
                             {
-                                bool change = false;
-                                //如果之前的是1 来源于区级,后面因区级删除,应该还原为0。
-                                var oldBlocks = old.blocks.Select(x => x.name).ToHashSet() ;
-                                var dimBlocks = dim.SelectMany(d => d.blocks);
-                                //增加的
-                                var addBlocks = dimBlocks.Except(oldBlocks);
-                                //减少的
-                                var cutBlocks = oldBlocks.Except(dimBlocks);
-                                foreach (var add in addBlocks) {
-                                    old.blocks.Add(new Block { name = add,source = 1 });
-                                    change = true;
-                                }
-                                //减少的还原为0
-                                if (cutBlocks.Any()) {
-                                    old.blocks.ForEach(ob => {
-                                        if (cutBlocks.Contains(ob.name))
+                                var subjects = artSetting.dimensions.FindAll(d => !string.IsNullOrWhiteSpace(d.subjectBind) && !string.IsNullOrWhiteSpace(d.subject) && d.subjectBind.Equals(unBindId))?.Select(m => m.subject);
+                                if (subjects != null)
+                                {
+                                    foreach (var subject in subjects)
+                                    {
+                                        //获取同名学科,且没绑定的
+                                        var sub = period.subjects.FindAll(sub => sub.name.Equals(subject) && string.IsNullOrWhiteSpace(sub.bindId));
+                                        if (sub.IsNotEmpty())
                                         {
-                                            ob.source = 0;
-                                            change=true;
+                                            sub[0].bindId = unBindId;
                                         }
-                                    });
-                                }
-                                if (change) {
-                                    await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync(old, old.id, new PartitionKey(old.code));
+                                        else
+                                        {
+                                            period.subjects.Add(new Subject { id = Guid.NewGuid().ToString(), name = subject, bindId = unBindId, type = 1 });
+
+                                        }
+                                        break;
+                                    }
                                 }
                             }
-                            else
+                        }
+                        var period_subjects = period.subjects.Where(s => !string.IsNullOrWhiteSpace(s.bindId));
+                        foreach (var subject in period_subjects)
+                        {
+                            var dim = dimension.Where(x => x.subjectBind.Equals(subject.bindId));
+                            if (dim.Any())
                             {
-                                var blocks = dim.SelectMany(x => x.blocks).Select(bs=> new Block { name=bs,source=-1 });
-                                if (blocks.Any()) {
-                                    var  _new = new Knowledge
+                                Knowledge old = null;
+                                string sql = $"select value(c) from c where c.periodId = '{period.id}'";
+                                string pk = $"Knowledge-{school.id}-{subject.id}";
+                                await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").
+                                    GetItemQueryIterator<Knowledge>(queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey(pk) }))
+                                {
+                                    old = item;
+                                    break;
+                                }
+
+                                //同步知识块。
+
+                                if (old != null)
+                                {
+                                    bool change = false;
+                                    //如果之前的是1 来源于区级,后面因区级删除,应该还原为0。
+                                    var oldBlocks = old.blocks.Select(x => x.name).ToHashSet();
+                                    var dimBlocks = dim.SelectMany(d => d.blocks);
+                                    //增加的
+                                    var addBlocks = dimBlocks.Except(oldBlocks);
+                                    //减少的
+                                    var cutBlocks = oldBlocks.Except(dimBlocks);
+                                    foreach (var add in addBlocks)
+                                    {
+                                        old.blocks.Add(new Block { name = add, source = 1 });
+                                        change = true;
+                                    }
+                                    //减少的还原为0
+                                    if (cutBlocks.Any())
                                     {
-                                        id = Guid.NewGuid().ToString(),
-                                        pk = "Knowledge",
-                                        code = pk,
-                                        owner = school.id,
-                                        periodId = period.id,
-                                        subjectId = subject.id,
-                                        blocks = blocks.ToList()
-                                    };
-                                    await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).CreateItemAsync(_new,  new PartitionKey(_new.code));
+                                        old.blocks.ForEach(ob => {
+                                            if (cutBlocks.Contains(ob.name))
+                                            {
+                                                ob.source = 0;
+                                                change = true;
+                                            }
+                                        });
+                                    }
+                                    if (change)
+                                    {
+                                        await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync(old, old.id, new PartitionKey(old.code));
+                                    }
+                                    var count = new { pcount = old.points != null ? old.points.Count : 0, bcount = old.blocks != null ? old.blocks.Count : 0 };
+                                    //处理知识点,知识块计数问题
+                                    await _azureRedis.GetRedisClient(8).HashSetAsync($"Knowledge:Count:{old.owner}-{old.subjectId}", old.periodId, count.ToJsonString());
+                                }
+                                else
+                                {
+                                    var blocks = dim.SelectMany(x => x.blocks).Select(bs => new Block { name = bs, source = -1 });
+                                    if (blocks.Any())
+                                    {
+                                        var _new = new Knowledge
+                                        {
+                                            id = Guid.NewGuid().ToString(),
+                                            pk = "Knowledge",
+                                            code = pk,
+                                            owner = school.id,
+                                            periodId = period.id,
+                                            subjectId = subject.id,
+                                            blocks = blocks.ToList()
+                                        };
+                                        await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).CreateItemAsync(_new, new PartitionKey(_new.code));
+                                        var count = new { pcount = _new.points != null ? _new.points.Count : 0, bcount = _new.blocks != null ? _new.blocks.Count : 0 };
+                                        //处理知识点,知识块计数问题
+                                        await _azureRedis.GetRedisClient(8).HashSetAsync($"Knowledge:Count:{_new.owner}-{_new.subjectId}", _new.periodId, count.ToJsonString());
+                                    }
                                 }
                             }
                         }
                     }
+                    await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync(school, school.id, new PartitionKey(school.code));
                 }
-                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync(school , school.id, new PartitionKey(school.code));
+                return response;
+            } catch (Exception ex) {
+                await _dingDing.SendBotMsg($"area-artsetting-change,{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
             }
             return response;
         }

+ 4 - 1
TEAMModelOS/Controllers/Normal/ArtSettingController.cs

@@ -42,8 +42,9 @@ namespace TEAMModelOS.Controllers
         private readonly AzureStorageFactory _azureStorage;
         private readonly AzureRedisFactory _azureRedis;
         public IConfiguration _configuration { get; set; }
+        private readonly HttpTrigger _httpTrigger;
         public ArtSettingController(AzureCosmosFactory azureCosmos, AzureServiceBusFactory serviceBus, SnowflakeId snowflakeId, DingDing dingDing,
-            IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, IConfiguration configuration)
+            IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, IConfiguration configuration, HttpTrigger httpTrigger)
         {
             _azureCosmos = azureCosmos;
             _serviceBus = serviceBus;
@@ -53,6 +54,7 @@ namespace TEAMModelOS.Controllers
             _azureStorage = azureStorage;
             _azureRedis = azureRedis;
             _configuration = configuration;
+            _httpTrigger = httpTrigger;
         }
         /// <param name="request"></param>
         /// <returns></returns>
@@ -205,6 +207,7 @@ namespace TEAMModelOS.Controllers
                         break;
                     default: break;
                 }
+                _ = _httpTrigger.RequestHttpTrigger(new { areaId = setting.id}, _option.Location, "area-artsetting-change");
                 await client.GetContainer(Constant.TEAMModelOS, Constant.Normal).ReplaceItemAsync<ArtSetting>(setting, setting.id, partitionKey: new Azure.Cosmos.PartitionKey("ArtSetting"));
                 return Ok(new { setting });
             }

+ 77 - 5
TEAMModelOS/Controllers/Third/Sc/ScDataPushController.cs

@@ -766,7 +766,28 @@ namespace TEAMModelOS.Controllers
                             switch (a.hpscore)
                             {
                                 case -1:
+                                    //如果互评未认定,则优先以校评为准。
                                     hpscore = "0";
+                                    if (a.xzscore == 1)
+                                    {
+                                        hpscore = "1";
+                                    }
+                                    else if (a.xzscore == 2)
+                                    {
+                                        hpscore = "2";
+                                    }
+                                    //如果互评未认定,且没有校评,则以自评为准
+                                    if (a.zpscore == 1)
+                                    {
+                                        hpscore = "1";
+                                        break;
+                                    }
+                                    else if (a.zpscore == 2)
+                                    {
+                                        hpscore = "2";
+                                        break;
+                                    }
+                                    //如果都没有,则未认定
                                     break;
                                 case 0:
                                     hpscore = "3";
@@ -785,7 +806,30 @@ namespace TEAMModelOS.Controllers
                             switch (a.xzscore)
                             {
                                 case -1:
+                                    //如果校评未认定,则优先以互评为准。
                                     xzpresult = "0";
+                                    if (a.hpscore == 1)
+                                    {
+                                        xzpresult = "1";
+                                        break;
+                                    }
+                                    else if (a.hpscore == 2)
+                                    {
+                                        xzpresult = "2";
+                                        break;
+                                    }
+                                    //如果校评未认定,且没有互评,则以自评为准
+                                    if (a.zpscore == 1)
+                                    {
+                                        xzpresult = "1";
+                                        break;
+                                    }
+                                    else if (a.zpscore == 2)
+                                    {
+                                        xzpresult = "2";
+                                        break;
+                                    }
+                                    //如果都没有,则未认定
                                     break;
                                 case 0:
                                     xzpresult = "3";
@@ -964,7 +1008,8 @@ namespace TEAMModelOS.Controllers
             }
             return Ok();
         }
-        private async Task GetYxData(ScAccessConfig config  , ScTeacher sc, List<PushData> datas ) {
+        private async Task<List<PushData> > GetYxData(ScAccessConfig config  , ScTeacher sc) {
+            List<PushData> datas = new List<PushData>();
             Dictionary<string, object> parameterContent53123 = new Dictionary<string, object>();
             parameterContent53123.Add("TrainComID", config.trainComID);
             parameterContent53123.Add("ProjectID", config.p.First().pd);
@@ -981,6 +1026,8 @@ namespace TEAMModelOS.Controllers
                 newPushData.teacherInfo.PXXD = pushData.teacherInfo.PXXD;
                 newPushData.teacherInfo.ComPassed = pushData.teacherInfo.ComPassed;
                 newPushData.teacherInfo.ComPassedTime = pushData.teacherInfo.ComPassedTime;
+                newPushData.diagnosisInfo = pushData.diagnosisInfo;
+                newPushData.files = pushData.files;
                 datas.Add(newPushData);
             }
             else {
@@ -988,6 +1035,7 @@ namespace TEAMModelOS.Controllers
                 newPushData.teacherInfo = new TeacherSc(sc);
                 datas.Add(newPushData);
             }
+            return datas;
         }
         /// <summary>
         /// 获取四川省已经上传的。
@@ -1039,12 +1087,36 @@ namespace TEAMModelOS.Controllers
             }
             List<PushData> ycData=   new List<PushData>();
             List<PushData> datas = new List<PushData>();
-            List<Task> tasks = new List<Task>();
+            List<Task<List<PushData>>> tasks = new List<Task<List<PushData>>>();
             scTeachers.ForEach(sc =>
             {
-                tasks.Add(GetYxData(config, sc, datas));
+                tasks.Add(GetYxData(config, sc));
+            });
+            List<TeacherSc> teachers = new List<TeacherSc>();
+            var tsk =  await tasks.TaskPage(100);
+            foreach (var a in tsk) {
+                datas.AddRange(a);
+            }
+            datas.ForEach(x => {
+                bool has0result = false;
+                if (x.diagnosisInfo != null)
+                {
+                    x.diagnosisInfo.ForEach(t =>
+                    {
+                        if (t.hpresult.Equals("0") || t.zpresult.Equals("0") || t.xzpresult.Equals("0"))
+                        {
+                            has0result = true;
+                        }
+                    });
+                }
+                else {
+                    has0result = true;
+                    teachers.Add(x.teacherInfo);
+                }
+                if (has0result && x.teacherInfo.ComPassed != 3 && x.teacherInfo.ComPassed != 0) {
+                    teachers.Add(x.teacherInfo);
+                }
             });
-            await tasks.TaskPage(100);
             List<KeyValuePair<string, string>> htmls = new List<KeyValuePair<string, string>>();
             var group= datas.GroupBy(x => x.teacherInfo.SchoolName);
             List<dynamic> okd = new List<dynamic>();
@@ -1101,7 +1173,7 @@ namespace TEAMModelOS.Controllers
                     data.teacherInfo.TID,
                 });
             });
-            return Ok(new { ycData= ycd, okData = okd });
+            return Ok(new { ycData= ycd, okData = okd , tmdid= teachers .Select(x=>x.tmdid)});
         }
     }