Browse Source

处理修改学校信息和顾问信息的问题

Li 2 years ago
parent
commit
ed3830af23

+ 53 - 152
TEAMModelBI/Controllers/BISchool/BatchSchoolController.cs

@@ -491,12 +491,12 @@ namespace TEAMModelBI.Controllers.BISchool
                     await _dingDing.SendBotMsg($"BI,{_option.Location} \n 单个建校信息:{noticeDD}", GroupNames.成都开发測試群組);
 
 
-              ////v2通知
-              //Teacher targetTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<Teacher>($"{_tmdId}", new PartitionKey($"Base"));
-              //_coreAPIHttpService.PushNotify(new List<IdNameCode> { new IdNameCode { id = targetTeacher.id, name = targetTeacher.name, code = targetTeacher.lang } }, "create-school", Constant.NotifyType_IES5_Management, new Dictionary<string, object> { { "tmdname", $"{_tmdName}" }, { "schooName", $"{vsSql}" } }, _option.Location, _configuration, _dingDing, _environment.ContentRootPath);
+                ////v2通知
+                //Teacher targetTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<Teacher>($"{_tmdId}", new PartitionKey($"Base"));
+                //_coreAPIHttpService.PushNotify(new List<IdNameCode> { new IdNameCode { id = targetTeacher.id, name = targetTeacher.name, code = targetTeacher.lang } }, "create-school", Constant.NotifyType_IES5_Management, new Dictionary<string, object> { { "tmdname", $"{_tmdName}" }, { "schooName", $"{vsSql}" } }, _option.Location, _configuration, _dingDing, _environment.ContentRootPath);
 
-              //保存操作记录
-              await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "school-batchAdd", stringBuilder?.ToString(), _dingDing, httpContext: HttpContext);
+                //保存操作记录
+                await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "school-batchAdd", stringBuilder?.ToString(), _dingDing, httpContext: HttpContext);
                 if (schools.Count == foundSchools.biSchools.Count || userScs.Count == foundSchools.biSchools.Count)
                     return Ok(new { state = RespondCode.CreateFailed, message = "已有部分学校批量创建成功;学校已经重复/学校信息有误!请检查学校信息!", schools, userScs });
                 else
@@ -603,7 +603,7 @@ namespace TEAMModelBI.Controllers.BISchool
 
                         if ($"{order}".Equals("desc"))
                             sqlTxt.Append(" order by c.createTime desc");
-                        else 
+                        else
                             sqlTxt.Append(" order by c.createTime asc");
 
                         await foreach (var itemSchool in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<AssistSchool>(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
@@ -785,7 +785,7 @@ namespace TEAMModelBI.Controllers.BISchool
                 List<string> schoolIds = new();
                 StringBuilder stringBuilder = new("select c.id,c.code,c.schoolCode,c.name,c.region,c.province,c.city,c.dist,c.size,c.address,c.picture,c.type,c.scale,c.areaId,c.standard from c ");
                 StringBuilder scCntSql = new($"select value(count(c.id)) from c");
-                
+
                 if (!string.IsNullOrEmpty($"{scId}") && string.IsNullOrEmpty($"{name}"))
                 {
                     stringBuilder.Append($" where c.id='{scId}'");
@@ -1086,7 +1086,7 @@ namespace TEAMModelBI.Controllers.BISchool
 
                     //创建学校信息中间件
                     //_ = _httpTrigger.RequestHttpTrigger(new { school = $"{tempShool}" }, _option.Location, "set-sc-birelation");
-                    await BIStats.SetSchoolBIRelation(cosmosClient, blobClient, tableClient, _dingDing, tempShool);
+                    //await BIStats.SetSchoolBIRelation(cosmosClient, blobClient, tableClient, _dingDing, tempShool);
 
                     //修改学校教师关联的信息
                     string sql = $"SELECT distinct value(c) FROM c join A1 in c.schools where A1.schoolId='{tempShool.id}'";
@@ -1107,158 +1107,59 @@ namespace TEAMModelBI.Controllers.BISchool
                         await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(item, item.id, new PartitionKey($"Base"));
                     }
 
-                    ////需要重大修改后保留
+                    //需要重大修改后保留
+                    BIRelation biRel = new();
+                    var respRel = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(tempShool.id, new PartitionKey("BIRel"));
+                    if (respRel.Status == 200)
+                    {
+                        using var fileJson = await JsonDocument.ParseAsync(respRel.ContentStream);
+                        biRel = fileJson.ToObject<BIRelation>();
+                    }
+                    else
+                    {
+                        biRel.id = tempShool.id;
+                    }
+
+                    string aName = null;
+                    if (!string.IsNullOrEmpty($"{tempShool.areaId}"))
+                    {
+                        aName = await CosmosQueryHelper.GetStr(cosmosClient, "Normal", $"select value(c.name) from c where c.id='{tempShool.areaId}'", "Base-Area");
+                    }
+
+                    biRel.name = tempShool.name;
+                    biRel.picture = tempShool.picture;
+                    biRel.region = tempShool.region;
+                    biRel.province = tempShool.province;
+                    biRel.city = tempShool.city;
+                    biRel.dist = tempShool.dist;
+                    biRel.address = tempShool.address;
+                    biRel.areaId = tempShool.areaId;
+                    biRel.size = tempShool.size;
+                    biRel.scale = tempShool.scale;
+                    biRel.upDate = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                    biRel.areaName = aName;
                     if (idInfos.Count > 0)
                     {
-                        BIRelation biRel = new();
-                        var respRel = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(tempShool.id,new PartitionKey("BIRel"));
-                        if (respRel.Status == 200)
-                        {
-                            using var fileJson = await JsonDocument.ParseAsync(respRel.ContentStream);
-                            biRel = fileJson.ToObject<BIRelation>();
-                        }
-                        else
-                            biRel.id = tempShool.id;
-
-                        string aName = null;
-                        if (!string.IsNullOrEmpty($"{tempShool.areaId}"))
-                            aName = await CosmosQueryHelper.GetStr(cosmosClient, "Normal", $"select value(c.name) from c where c.id='{tempShool.areaId}'", "Base-Area");
-
-                        biRel.name = tempShool.name;
-                        biRel.picture = tempShool.picture;
-                        biRel.region = tempShool.region;
-                        biRel.province = tempShool.province;
-                        biRel.city = tempShool.city;
-                        biRel.dist = tempShool.dist;
-                        biRel.address = tempShool.address;
-                        biRel.areaId = tempShool.areaId;
-                        biRel.size = tempShool.size;
-                        biRel.scale = tempShool.scale;
-                        biRel.upDate = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
-                        biRel.areaName = aName;
                         foreach (var item in idInfos)
                         {
                             var tempAss = biRel.assists.Find(f => f.id.Equals(item.id));
-                            if (tempAss == null) 
+                            if (tempAss == null)
                                 biRel.assists.Add(item);
                         }
-
-                        if (respRel.Status == 200)
-                            await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<BIRelation>(biRel, biRel.id, new PartitionKey("BIRel"));
-                        else
-                            await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<BIRelation>(biRel, new PartitionKey("BIRel"));
+                    }
+                    else
+                    {
+                        biRel.assists = idInfos;
                     }
 
-                    ////需要重大修改后移除
-                    //jsonElement.TryGetProperty("assistId", out JsonElement _assistId);  //对接V2.0 删除该信息
-                    //List<string> assistId = _assistId.ToObject<List<string>>();
-                    //List<string> periodS = period.ToObject<List<string>>();
-                    //Dictionary<string, List<Dictionary<string, string>>> haveSchoolManger = new();
-                    //if (assistId.Count > 0)
-                    //{
-                    //    //修改学校顾问
-                    //    string sqlTxt = $"SELECT value(c) From c WHERE ARRAY_CONTAINS(c.roles,'assist',true)";
-                    //    List<SchoolTeacher> schoolTeachers = new();
-                    //    await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<SchoolTeacher>(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{tempShool.id}") }))
-                    //    {
-                    //        if (!assistId.Contains(item.id))
-                    //        {
-                    //            if (item.roles.Contains("assist"))
-                    //            {
-                    //                item.roles.Remove("assist");
-                    //                if (item.roles.Count > 0)
-                    //                {
-                    //                    await cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<SchoolTeacher>(item, item.id, new PartitionKey(item.code));
-                    //                }
-                    //                else
-                    //                {
-                    //                    await cosmosClient.GetContainer("TEAMModelOS", "School").DeleteItemAsync<SchoolTeacher>(item.id, new PartitionKey(item.code));
-                    //                }
-                    //            }
-                    //        }
-                    //    }
-
-                    //    foreach (var itemTeacher in assistId)
-                    //    {
-                    //        Teacher tempTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>($"{itemTeacher}", new PartitionKey("Base"));
-                    //        if (tempTeacher != null)
-                    //        {
-                    //            var haveTeacher = tempTeacher.schools.Find(x => x.schoolId.Equals($"{_schoolId}"));
-                    //            if (haveTeacher == null)
-                    //            {
-                    //                Teacher.TeacherSchool teacherSchool = new()
-                    //                {
-                    //                    schoolId = tempShool.id,
-                    //                    name = tempShool.name,
-                    //                    status = "join",
-                    //                    time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
-                    //                    picture = tempShool.picture,
-                    //                    areaId = tempShool.areaId
-                    //                };
-                    //                tempTeacher.schools.Add(teacherSchool);
-                    //                //给醍摩豆顾问添加学校
-                    //                await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(tempTeacher, tempTeacher.id, new PartitionKey($"Base"));
-
-                    //                ////不存在则在原来的基础上添加顾问角色
-                    //                //SchoolTeacher addSchoolTeacher = new()
-                    //                //{
-                    //                //    id = itemTeacher,
-                    //                //    code = $"Teacher-{tempShool.id}",
-                    //                //    pk = "Teacher",
-                    //                //    status = "join",
-                    //                //    roles = new List<string>() { "assist" },
-                    //                //    name = tempTeacher.name,
-                    //                //    job = $"{tempShool.name}-顾问",
-                    //                //    size = 0,
-                    //                //    createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
-                    //                //};
-
-                    //                //var resScTch = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{itemTeacher}", new PartitionKey($"Teacher-{tempShool.id}"));
-                    //                //if(resScTch.)
-
-                    //                ////添加学校学校顾问
-                    //                //await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(addSchoolTeacher, new PartitionKey($"Teacher-{tempShool.id}"));
-                    //            }
-
-                    //            //查询该教师是否存在该校
-                    //            SchoolTeacher schoolTeacher = null;
-                    //            var resScTch = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{itemTeacher}", new PartitionKey($"Teacher-{tempShool.id}"));
-                    //            if (resScTch.Status == 200)
-                    //            {
-                    //                using var tchJson = await JsonDocument.ParseAsync(resScTch.ContentStream);
-                    //                schoolTeacher = tchJson.ToObject<SchoolTeacher>();
-                    //            }
-
-                    //            if (schoolTeacher != null)
-                    //            {
-                    //                if (!schoolTeacher.roles.Contains("assist"))
-                    //                {
-                    //                    schoolTeacher.roles.Add("assist");
-                    //                    //添加顾问权限
-                    //                    await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<SchoolTeacher>(schoolTeacher, schoolTeacher.id, new PartitionKey($"Teacher-{tempShool.id}"));
-                    //                }
-                    //            }
-                    //            else
-                    //            {
-                    //                SchoolTeacher addSchoolTeacher = new()
-                    //                {
-                    //                    id = itemTeacher,
-                    //                    code = $"Teacher-{tempShool.id}",
-                    //                    pk = "Teacher",
-                    //                    status = "join",
-                    //                    roles = new List<string>() { "assist" },
-                    //                    name = tempTeacher.name,
-                    //                    job = $"{tempShool.name}-顾问",
-                    //                    size = 0,
-                    //                    createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
-                    //                };
-                    //                //添加学校顾问
-                    //                await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(addSchoolTeacher, new PartitionKey($"Teacher-{tempShool.id}"));
-                    //            }
-                    //        }
-                    //    }
-                    //}
-
+                    if (respRel.Status == 200)
+                    {
+                        await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<BIRelation>(biRel, biRel.id, new PartitionKey("BIRel"));
+                    }
+                    else
+                    {
+                        await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<BIRelation>(biRel, new PartitionKey("BIRel"));
+                    }
                 }
 
                 //保存操作记录
@@ -1266,7 +1167,7 @@ namespace TEAMModelBI.Controllers.BISchool
 
                 return Ok(new { state = 200 });
             }
-            catch (Exception ex) 
+            catch (Exception ex)
             {
                 await _dingDing.SendBotMsg($"BI,  {_option.Location}   /batchschool/upd-schoolassist   \n  {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
                 return BadRequest();

+ 30 - 0
TEAMModelOS.SDK/Models/Cosmos/BI/BICommon/PersonalStats.cs

@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TEAMModelOS.SDK.Models.Cosmos.BI.BICommon
+{
+    public class PersonalStats : CosmosEntity
+    {
+        /// <summary>
+        /// id   2022-tmdid
+        /// 
+        /// </summary>
+        public PersonalStats()
+        {
+            pk = "Statistics";
+            code = "PersonalStats";
+        }
+
+        public string tmdId { get; set; }
+
+        public List<double> stuCnt{ get; set; }
+
+
+
+
+
+    }
+}