Selaa lähdekoodia

BI追加虛擬學校:
1.學校一覽追加虛擬學校
2.無學區學校列表追加虛擬學校
3.已加入學區學校追加虛擬學校
4.學區追加虛擬學校
5.學區移除虛擬學校
6.編輯虛擬學校(前端請關閉管理者及學段編輯分頁)

jeff 2 vuotta sitten
vanhempi
commit
5f23a06c5d

+ 2 - 0
TEAMModelBI/ClientApp/src/view/areaServe/areamanage.vue

@@ -819,6 +819,7 @@ export default {
         schoolCode: [addSchoolitem.value.id],
         schoolCode: [addSchoolitem.value.id],
         standard: currentlySelect.value.standard,
         standard: currentlySelect.value.standard,
         areaId: currentlySelect.value.id,
         areaId: currentlySelect.value.id,
+        code: [addSchoolitem.value.code],
         // schoolCode: [schoolcode],
         // schoolCode: [schoolcode],
       }
       }
       proxy.$api.areaAddSchool(data).then(async (res) => {
       proxy.$api.areaAddSchool(data).then(async (res) => {
@@ -940,6 +941,7 @@ export default {
             let data = {
             let data = {
               areaId: currentlySelect.value.id,
               areaId: currentlySelect.value.id,
               schoolId: datas.id,
               schoolId: datas.id,
+              code: datas.code,
               isDefault: states,
               isDefault: states,
             }
             }
             proxy.$api.areaDeleSchool(data).then(async (res) => {
             proxy.$api.areaDeleSchool(data).then(async (res) => {

+ 1 - 1
TEAMModelBI/ClientApp/src/view/schoolServe/school.vue

@@ -1225,7 +1225,7 @@ export default {
     }
     }
     function removeSchool (value, index) {
     function removeSchool (value, index) {
       console.log(value, index)
       console.log(value, index)
-      let data = { schoolId: [value.id] }
+      let data = { schoolId: [value.id], code: [value.code] }
       ElMessageBox.confirm(`您确定要删除 ${value.name} 学校吗? 请慎重操作!`, '删除学校', {
       ElMessageBox.confirm(`您确定要删除 ${value.name} 学校吗? 请慎重操作!`, '删除学校', {
         confirmButtonText: proxy.$t(`commonMsg.confirm`),
         confirmButtonText: proxy.$t(`commonMsg.confirm`),
         cancelButtonText: proxy.$t(`commonMsg.closes`),
         cancelButtonText: proxy.$t(`commonMsg.closes`),

+ 1 - 0
TEAMModelBI/ClientApp/src/view/schoolmanage/schoolManege.vue

@@ -495,6 +495,7 @@ export default {
         }
         }
       }
       }
       let updateForm = {
       let updateForm = {
+        code: nowPitchdata.value.code,
         name: nowPitchdata.value.name,
         name: nowPitchdata.value.name,
         schoolId: nowPitchdata.value.id,
         schoolId: nowPitchdata.value.id,
         picture: nowPitchdata.value.picture,
         picture: nowPitchdata.value.picture,

+ 38 - 6
TEAMModelBI/Controllers/BINormal/AreaRelevantController.cs

@@ -72,13 +72,13 @@ namespace TEAMModelBI.Controllers.BINormal
                 if (!string.IsNullOrEmpty($"{_isDefalue}"))
                 if (!string.IsNullOrEmpty($"{_isDefalue}"))
                     isManyArea = true;
                     isManyArea = true;
                 List<JoinAreaSchool> joinAreaSchools = new();
                 List<JoinAreaSchool> joinAreaSchools = new();
-                string sqltxt = $"SELECT c.id,c.name,c.schoolCode,c.province,c.city,c.dist,c.picture,c.period,c.areaId,c.standard,c.manyAreas FROM c WHERE c.areaId='{_areaId}'";
+                string sqltxt = $"SELECT c.code,c.id,c.name,c.schoolCode,c.province,c.city,c.dist,c.picture,c.period,c.areaId,c.standard,c.manyAreas FROM c WHERE c.areaId='{_areaId}'";
 
 
                 if (isManyArea)
                 if (isManyArea)
                 {
                 {
-                    sqltxt = $"SELECT c.id,c.name,c.schoolCode,c.province,c.city,c.dist,c.picture,c.period,c.areaId,c.standard,c.manyAreas FROM c join m in c.manyAreas WHERE (c.areaId ='{_areaId}' or m.areaId='{_areaId}')";
+                    sqltxt = $"SELECT c.code,c.id,c.name,c.schoolCode,c.province,c.city,c.dist,c.picture,c.period,c.areaId,c.standard,c.manyAreas FROM c join m in c.manyAreas WHERE (c.areaId ='{_areaId}' or m.areaId='{_areaId}')";
                 }
                 }
-
+                //IES5實體學校
                 await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: sqltxt, requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey("Base")})) 
                 await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: sqltxt, requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey("Base")})) 
                 {
                 {
                     using var json = await JsonDocument.ParseAsync(item.ContentStream);
                     using var json = await JsonDocument.ParseAsync(item.ContentStream);
@@ -88,6 +88,7 @@ namespace TEAMModelBI.Controllers.BINormal
                         {
                         {
                             JoinAreaSchool joinAreaSchool = new()
                             JoinAreaSchool joinAreaSchool = new()
                             {
                             {
+                                code = obj.GetProperty("code").GetString(),
                                 id = obj.GetProperty("id").GetString(),
                                 id = obj.GetProperty("id").GetString(),
                                 name = obj.GetProperty("name").GetString(),
                                 name = obj.GetProperty("name").GetString(),
                                 schoolCode = obj.GetProperty("schoolCode").GetString(),
                                 schoolCode = obj.GetProperty("schoolCode").GetString(),
@@ -116,6 +117,32 @@ namespace TEAMModelBI.Controllers.BINormal
                         }                    
                         }                    
                     }
                     }
                 }
                 }
+                //虛擬學校
+                await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: sqltxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("VirtualBase") }))
+                {
+                    using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                    {
+                        foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                        {
+                            JoinAreaSchool joinAreaSchool = new()
+                            {
+                                code = obj.GetProperty("code").GetString(),
+                                id = obj.GetProperty("id").GetString(),
+                                name = obj.GetProperty("name").GetString(),
+                                schoolCode = obj.GetProperty("schoolCode").GetString(),
+                                province = obj.GetProperty("province").GetString(),
+                                city = obj.GetProperty("city").GetString(),
+                                dist = obj.GetProperty("dist").GetString(),
+                                picture = obj.GetProperty("picture").GetString(),
+                                period = obj.GetProperty("period").ToObject<List<Period>>().Select(x => x.name).ToList(),
+                                areaId = obj.GetProperty("areaId").GetString(),
+                                standard = obj.GetProperty("standard").GetString()
+                            };
+                            joinAreaSchools.Add(joinAreaSchool);
+                        }
+                    }
+                }
 
 
                 return Ok(new { state = 200, joinAreaSchools });
                 return Ok(new { state = 200, joinAreaSchools });
             }
             }
@@ -139,6 +166,7 @@ namespace TEAMModelBI.Controllers.BINormal
             try
             try
             {
             {
                 if (!jsonElement.TryGetProperty("schoolId", out JsonElement schoolId)) return BadRequest();
                 if (!jsonElement.TryGetProperty("schoolId", out JsonElement schoolId)) return BadRequest();
+                string code = (jsonElement.TryGetProperty("code", out JsonElement codeJobj)) ? codeJobj.GetString() : "Base";
                 jsonElement.TryGetProperty("areaId", out JsonElement areaId);
                 jsonElement.TryGetProperty("areaId", out JsonElement areaId);
                 jsonElement.TryGetProperty("standard", out JsonElement standard);
                 jsonElement.TryGetProperty("standard", out JsonElement standard);
                 jsonElement.TryGetProperty("isDefault", out JsonElement isDefault);
                 jsonElement.TryGetProperty("isDefault", out JsonElement isDefault);
@@ -165,7 +193,7 @@ namespace TEAMModelBI.Controllers.BINormal
                         return Ok(new { state = 401, msg = "区域已经规定了,不能切换能能力" });
                         return Ok(new { state = 401, msg = "区域已经规定了,不能切换能能力" });
                 }
                 }
 
 
-                School tempSchool = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{schoolId}", new PartitionKey("Base"));
+                School tempSchool = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{schoolId}", new PartitionKey($"{code}"));
                 if (bool.Parse($"{isDefault}") == true)
                 if (bool.Parse($"{isDefault}") == true)
                 {
                 {
                     tempSchool.areaId = null;
                     tempSchool.areaId = null;
@@ -206,11 +234,14 @@ namespace TEAMModelBI.Controllers.BINormal
                         }
                         }
                     }
                     }
                 }
                 }
-                School school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(tempSchool, tempSchool.id, new PartitionKey("Base"));
+                School school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(tempSchool, tempSchool.id, new PartitionKey($"{code}"));
 
 
                 //创建/修改学校信息中间件
                 //创建/修改学校信息中间件
                 //_ = _httpTrigger.RequestHttpTrigger(new { school = $"{school}" }, _option.Location, "set-sc-birelation");
                 //_ = _httpTrigger.RequestHttpTrigger(new { school = $"{school}" }, _option.Location, "set-sc-birelation");
-                await BIStats.SetSchoolBIRelation(cosmosClient, blobClient, tableClient, _dingDing, school);
+                if (school.code.Equals("Base")) //實體學校更新BI中間件
+                {
+                    await BIStats.SetSchoolBIRelation(cosmosClient, blobClient, tableClient, _dingDing, school);
+                }
 
 
                 //保存操作记录
                 //保存操作记录
                 await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "school-update", $"{_tmdName}【{_tmdId}】已操作学校(ID:{schoolId})移除已区域(ID:{areaId})", _dingDing, httpContext: HttpContext);
                 await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "school-update", $"{_tmdName}【{_tmdId}】已操作学校(ID:{schoolId})移除已区域(ID:{areaId})", _dingDing, httpContext: HttpContext);
@@ -589,6 +620,7 @@ namespace TEAMModelBI.Controllers.BINormal
         /// </summary>
         /// </summary>
         public record JoinAreaSchool
         public record JoinAreaSchool
         {
         {
+            public string code { get; set; }
             public string id { get; set; }
             public string id { get; set; }
             public string name { get; set; }
             public string name { get; set; }
             public string schoolCode { get; set; }
             public string schoolCode { get; set; }

+ 139 - 95
TEAMModelBI/Controllers/BISchool/BatchSchoolController.cs

@@ -1042,7 +1042,7 @@ namespace TEAMModelBI.Controllers.BISchool
                 jsonElement.TryGetProperty("city", out JsonElement city);
                 jsonElement.TryGetProperty("city", out JsonElement city);
                 jsonElement.TryGetProperty("dist", out JsonElement dist);
                 jsonElement.TryGetProperty("dist", out JsonElement dist);
                 jsonElement.TryGetProperty("address", out JsonElement address);
                 jsonElement.TryGetProperty("address", out JsonElement address);
-
+                string code = (jsonElement.TryGetProperty("code", out JsonElement _code))? _code.GetString() : string.Empty;
                 jsonElement.TryGetProperty("assist", out JsonElement assist);
                 jsonElement.TryGetProperty("assist", out JsonElement assist);
                 List<IdInfo> idInfos = assist.ToObject<List<IdInfo>>();
                 List<IdInfo> idInfos = assist.ToObject<List<IdInfo>>();
                 //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
                 //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
@@ -1060,114 +1060,158 @@ namespace TEAMModelBI.Controllers.BISchool
                 //    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
                 //    blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
                 //}
                 //}
 
 
-                School tempShool = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{_schoolId}", new PartitionKey("Base"));
-                if (tempShool != null)
+                //IES5 實體學校變更
+                if (!code.Equals("VirtualBase"))
                 {
                 {
-                    List<Period> periods = new();
-                    string campusId = Guid.NewGuid().ToString();
-                    //periodS.ForEach(x =>
-                    //{
-                    //    periods.Add(new Period { id = Guid.NewGuid().ToString(), name = x.ToString(), campusId = campusId });
-                    //});
-
-                    //tempShool.period = periods;
-                    tempShool.size = !string.IsNullOrEmpty($"{size}") ? int.Parse($"{size}") : tempShool.size;
-                    tempShool.scale = !string.IsNullOrEmpty($"{scale}") ? int.Parse($"{scale}") : tempShool.scale;
-                    tempShool.picture = $"{picture}";
-                    tempShool.type = int.Parse($"{_type}");
-                    tempShool.name = $"{schoolName}";
-                    tempShool.areaId = $"{areaId}";
-                    tempShool.standard = $"{standard}";
-                    tempShool.province = string.IsNullOrEmpty($"{province}") ? tempShool.province : $"{province}";
-                    tempShool.city = string.IsNullOrEmpty($"{city}") ? tempShool.city : $"{city}";
-                    tempShool.dist = string.IsNullOrEmpty($"{dist}") ? tempShool.dist : $"{dist}";
-                    tempShool.address = string.IsNullOrEmpty($"{address}") ? tempShool.address : $"{address}";
-
-                    //修改学校
-                    await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(tempShool, tempShool.id, new PartitionKey("Base"));
-
-                    //创建学校信息中间件
-                    //_ = _httpTrigger.RequestHttpTrigger(new { school = $"{tempShool}" }, _option.Location, "set-sc-birelation");
-                    //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}'";
-                    List<Teacher> teachers = new();
-                    await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
-                    {
-                        teachers.Add(item);
-                    }
-                    foreach (var item in teachers)
+                    School tempShool = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{_schoolId}", new PartitionKey("Base"));
+                    if (tempShool != null)
                     {
                     {
-                        Teacher.TeacherSchool teacherSchool = item.schools.Find(x => x.schoolId.Equals(tempShool.id));
-                        if (teacherSchool != null)
+                        List<Period> periods = new();
+                        string campusId = Guid.NewGuid().ToString();
+                        //periodS.ForEach(x =>
+                        //{
+                        //    periods.Add(new Period { id = Guid.NewGuid().ToString(), name = x.ToString(), campusId = campusId });
+                        //});
+
+                        //tempShool.period = periods;
+                        tempShool.size = !string.IsNullOrEmpty($"{size}") ? int.Parse($"{size}") : tempShool.size;
+                        tempShool.scale = !string.IsNullOrEmpty($"{scale}") ? int.Parse($"{scale}") : tempShool.scale;
+                        tempShool.picture = $"{picture}";
+                        tempShool.type = int.Parse($"{_type}");
+                        tempShool.name = $"{schoolName}";
+                        tempShool.areaId = $"{areaId}";
+                        tempShool.standard = $"{standard}";
+                        tempShool.province = string.IsNullOrEmpty($"{province}") ? tempShool.province : $"{province}";
+                        tempShool.city = string.IsNullOrEmpty($"{city}") ? tempShool.city : $"{city}";
+                        tempShool.dist = string.IsNullOrEmpty($"{dist}") ? tempShool.dist : $"{dist}";
+                        tempShool.address = string.IsNullOrEmpty($"{address}") ? tempShool.address : $"{address}";
+                        //計算學校版本
+                        List<SchoolProductSumData> services = new List<SchoolProductSumData>();
+                        Azure.Response productSumResponse = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{_schoolId}", new PartitionKey("ProductSum"));
+                        if (productSumResponse.Status == 200)
                         {
                         {
-                            teacherSchool.name = tempShool.name;
-                            teacherSchool.picture = tempShool.picture;
-                            teacherSchool.areaId = tempShool.areaId;
+                            var doc = JsonDocument.Parse(productSumResponse.Content);
+                            if (doc.RootElement.TryGetProperty("service", out JsonElement service))
+                            {
+                                services.AddRange(service.ToObject<List<SchoolProductSumData>>());
+                            }
                         }
                         }
-                        await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(item, item.id, new PartitionKey($"Base"));
-                    }
+                        tempShool.edition = BISchoolService.calSchoolEdition(tempShool, services.Select(s => s.prodCode).ToList());
 
 
-                    //需要重大修改后保留
-                    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;
-                    }
+                        //修改学校
+                        await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(tempShool, tempShool.id, new PartitionKey("Base"));
 
 
-                    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");
-                    }
+                        //创建学校信息中间件
+                        //await BIStats.SetSchoolBIRelation(cosmosClient, blobClient, tableClient, _dingDing, tempShool);
 
 
-                    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)
-                    {
-                        foreach (var item in idInfos)
+                        //修改学校教师关联的信息
+                        string sql = $"SELECT distinct value(c) FROM c join A1 in c.schools where A1.schoolId='{tempShool.id}'";
+                        List<Teacher> teachers = new();
+                        await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
                         {
                         {
-                            var tempAss = biRel.assists.Find(f => f.id.Equals(item.id));
-                            if (tempAss == null)
-                                biRel.assists.Add(item);
+                            teachers.Add(item);
+                        }
+                        foreach (var item in teachers)
+                        {
+                            Teacher.TeacherSchool teacherSchool = item.schools.Find(x => x.schoolId.Equals(tempShool.id));
+                            if (teacherSchool != null)
+                            {
+                                teacherSchool.name = tempShool.name;
+                                teacherSchool.picture = tempShool.picture;
+                                teacherSchool.areaId = tempShool.areaId;
+                            }
+                            await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(item, item.id, new PartitionKey($"Base"));
                         }
                         }
-                    }
-                    else
-                    {
-                        biRel.assists = idInfos;
-                    }
 
 
-                    if (respRel.Status == 200)
-                    {
-                        await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<BIRelation>(biRel, biRel.id, new PartitionKey("BIRel"));
+                        //学校信息中间件更新
+                        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;
+                        biRel.edition = tempShool.edition;
+                        if (idInfos.Count > 0)
+                        {
+                            foreach (var item in idInfos)
+                            {
+                                var tempAss = biRel.assists.Find(f => f.id.Equals(item.id));
+                                if (tempAss == null)
+                                    biRel.assists.Add(item);
+                            }
+                        }
+                        else
+                        {
+                            biRel.assists = idInfos;
+                        }
+
+                        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
+                    
+                    //保存操作记录
+                    await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "school-update", $"{_tmdName}【{_tmdId}】修改学校功能,修改的学校:{_schoolId},{_type},{picture},{size},{idInfos.ToArray()}", _dingDing, httpContext: HttpContext);
+
+                    return Ok(new { state = 200 });
+                }
+                //IES5 虛擬學校變更
+                else
+                {
+                    VirtualBase tempVirtual = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<VirtualBase>($"{_schoolId}", new PartitionKey("VirtualBase"));
+                    if (tempVirtual != null)
                     {
                     {
-                        await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<BIRelation>(biRel, new PartitionKey("BIRel"));
+                        tempVirtual.picture = $"{picture}";
+                        tempVirtual.type = int.Parse($"{_type}");
+                        tempVirtual.name = $"{schoolName}";
+                        tempVirtual.areaId = $"{areaId}";
+                        tempVirtual.standard = $"{standard}";
+                        tempVirtual.province = string.IsNullOrEmpty($"{province}") ? tempVirtual.province : $"{province}";
+                        tempVirtual.city = string.IsNullOrEmpty($"{city}") ? tempVirtual.city : $"{city}";
+                        tempVirtual.dist = string.IsNullOrEmpty($"{dist}") ? tempVirtual.dist : $"{dist}";
+                        tempVirtual.address = string.IsNullOrEmpty($"{address}") ? tempVirtual.address : $"{address}";
+                        string aName = null;
+                        if (!string.IsNullOrEmpty($"{tempVirtual.areaId}"))
+                        {
+                            aName = await CosmosQueryHelper.GetStr(cosmosClient, "Normal", $"select value(c.name) from c where c.id='{tempVirtual.areaId}'", "Base-Area");
+                        }
+                        tempVirtual.areaName = aName;
+                        //修改学校
+                        await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<VirtualBase>(tempVirtual, tempVirtual.id, new PartitionKey("VirtualBase"));
                     }
                     }
+                    // 保存操作记录
+                    await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "school-update", $"{_tmdName}【{_tmdId}】修改学校功能,修改的学校:{_schoolId},{_type},{picture},{size},{idInfos.ToArray()}", _dingDing, httpContext: HttpContext);
+                    return Ok(new { state = 200 });
                 }
                 }
-
-                //保存操作记录
-                await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "school-update", $"{_tmdName}【{_tmdId}】修改学校功能,修改的学校:{_schoolId},{_type},{picture},{size},{idInfos.ToArray()}", _dingDing, httpContext: HttpContext);
-
-                return Ok(new { state = 200 });
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {

+ 123 - 74
TEAMModelBI/Controllers/BISchool/SchoolController.cs

@@ -180,39 +180,43 @@ namespace TEAMModelBI.Controllers.BISchool
             try
             try
             {
             {
                 var cosmosClient = _azureCosmos.GetCosmosClient();
                 var cosmosClient = _azureCosmos.GetCosmosClient();
+                var partitionKeys = new List<string>{"Base","VirtualBase"};
                 //StringBuilder sqltxt = new($"SELECT c.id,c.name,c.schoolCode,c.province,c.city,c.dist,c.picture,c.period,c.areaId,c.standard,c.manyAreas FROM c WHERE c.pk='School' and (c.areaId = '' or c.areaId = null or IS_DEFINED(c.areaId) = false)");
                 //StringBuilder sqltxt = new($"SELECT c.id,c.name,c.schoolCode,c.province,c.city,c.dist,c.picture,c.period,c.areaId,c.standard,c.manyAreas FROM c WHERE c.pk='School' and (c.areaId = '' or c.areaId = null or IS_DEFINED(c.areaId) = false)");
                 string sqltxt = $"SELECT value(c) FROM c WHERE (c.areaId = '' or c.areaId = null or IS_DEFINED(c.areaId) = false)";
                 string sqltxt = $"SELECT value(c) FROM c WHERE (c.areaId = '' or c.areaId = null or IS_DEFINED(c.areaId) = false)";
                 List<NotAreaSchool> notAreaSchools = new();
                 List<NotAreaSchool> notAreaSchools = new();
-                await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: sqltxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
+                foreach (string pk in partitionKeys)
                 {
                 {
-                    using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                    await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: sqltxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{pk}") }))
                     {
                     {
-                        foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                        using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                        if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
                         {
                         {
-                            NotAreaSchool notAreaSchool = new()
-                            {
-                                id = obj.GetProperty("id").GetString(),
-                                name = obj.GetProperty("name").GetString(),
-                                schoolCode = obj.GetProperty("schoolCode").GetString(),
-                                picture = obj.GetProperty("picture").GetString(),
-                                period = obj.GetProperty("period").ToObject<List<Period>>().Select(x => x.name).ToList(),
-                                province = obj.GetProperty("province").GetString(),
-                                city = obj.GetProperty("city").GetString()
-                            };
-                            try
+                            foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
                             {
                             {
-                                notAreaSchool.dist = obj.GetProperty("dist").GetString();
-                                notAreaSchool.areaId = obj.GetProperty("areaId").GetString();
-                                notAreaSchool.standard = obj.GetProperty("standard").GetString();
-                                notAreaSchool.areas = obj.GetProperty("manyAreas").ToObject<List<SchoolArea>>();
+                                NotAreaSchool notAreaSchool = new()
+                                {
+                                    code = obj.GetProperty("code").GetString(),
+                                    id = obj.GetProperty("id").GetString(),
+                                    name = obj.GetProperty("name").GetString(),
+                                    schoolCode = obj.GetProperty("schoolCode").GetString(),
+                                    picture = obj.GetProperty("picture").GetString(),
+                                    period = obj.GetProperty("period").ToObject<List<Period>>().Select(x => x.name).ToList(),
+                                    province = obj.GetProperty("province").GetString(),
+                                    city = obj.GetProperty("city").GetString()
+                                };
+                                try
+                                {
+                                    notAreaSchool.dist = obj.GetProperty("dist").GetString();
+                                    notAreaSchool.areaId = obj.GetProperty("areaId").GetString();
+                                    notAreaSchool.standard = obj.GetProperty("standard").GetString();
+                                    notAreaSchool.areas = obj.GetProperty("manyAreas").ToObject<List<SchoolArea>>();
+                                }
+                                catch { }
+                                notAreaSchools.Add(notAreaSchool);
                             }
                             }
-                            catch { }
-                            notAreaSchools.Add(notAreaSchool);
                         }
                         }
                     }
                     }
                 }
                 }
-
                 return Ok(new { state = 200, notAreaSchools });
                 return Ok(new { state = 200, notAreaSchools });
             }
             }
             catch (Exception ex)
             catch (Exception ex)
@@ -239,6 +243,7 @@ namespace TEAMModelBI.Controllers.BISchool
                 if (!jsonElement.TryGetProperty("areaId", out JsonElement _areaId)) return BadRequest();
                 if (!jsonElement.TryGetProperty("areaId", out JsonElement _areaId)) return BadRequest();
                 jsonElement.TryGetProperty("areaName", out JsonElement areaName);
                 jsonElement.TryGetProperty("areaName", out JsonElement areaName);
                 jsonElement.TryGetProperty("isDefault", out JsonElement isDefault);
                 jsonElement.TryGetProperty("isDefault", out JsonElement isDefault);
+                List<string> codes = (jsonElement.TryGetProperty("code", out JsonElement codeJobj)) ? codeJobj.ToObject<List<string>>() : new List<string>();
                 //jsonElement.TryGetProperty("site", out JsonElement site); //分开部署,就不需要,一站多用时,取消注释
                 //jsonElement.TryGetProperty("site", out JsonElement site); //分开部署,就不需要,一站多用时,取消注释
                 var isManyArea = false;
                 var isManyArea = false;
                 if (!string.IsNullOrEmpty($"{isDefault}"))
                 if (!string.IsNullOrEmpty($"{isDefault}"))
@@ -246,6 +251,13 @@ namespace TEAMModelBI.Controllers.BISchool
 
 
                 var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
                 var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
                 List<string> schoolCodes = _schoolCode.ToObject<List<string>>();
                 List<string> schoolCodes = _schoolCode.ToObject<List<string>>();
+                if(schoolCodes.Count > 0 && codes.Count.Equals(0)) //分區鍵值初始化
+                {
+                    for (int i = 0; i < schoolCodes.Count; i++)
+                    {
+                        codes.Add("Base");
+                    }
+                }
 
 
                 StringBuilder msg = new($"{_tmdName}【{_tmdId}】操作学校加入区域功能,加入的区域:{standard},学校ID:{string.Join("|", schoolCodes.ToArray())}");
                 StringBuilder msg = new($"{_tmdName}【{_tmdId}】操作学校加入区域功能,加入的区域:{standard},学校ID:{string.Join("|", schoolCodes.ToArray())}");
                 var cosmosClient = _azureCosmos.GetCosmosClient();
                 var cosmosClient = _azureCosmos.GetCosmosClient();
@@ -272,7 +284,9 @@ namespace TEAMModelBI.Controllers.BISchool
                 {
                 {
                     foreach (var tempCode in schoolCodes)
                     foreach (var tempCode in schoolCodes)
                     {
                     {
-                        School school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(tempCode, new PartitionKey("Base"));
+                        int index = schoolCodes.IndexOf(tempCode);
+                        string code = codes[index];
+                        School school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(tempCode, new PartitionKey($"{code}"));
                         if (school != null)
                         if (school != null)
                         {
                         {
                             if (isManyArea)
                             if (isManyArea)
@@ -311,7 +325,10 @@ namespace TEAMModelBI.Controllers.BISchool
                                 await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(item, item.id, new PartitionKey("Base"));
                                 await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(item, item.id, new PartitionKey("Base"));
                             }
                             }
                             await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(school, school.id, new PartitionKey(school.code));
                             await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(school, school.id, new PartitionKey(school.code));
-                            await BIStats.SetSchoolBIRelation(cosmosClient, blobClient, tableClient, _dingDing, school);
+                            if (school.code.Equals("Base"))
+                            {
+                                await BIStats.SetSchoolBIRelation(cosmosClient, blobClient, tableClient, _dingDing, school);
+                            }
                         }
                         }
                     }
                     }
                 }
                 }
@@ -352,7 +369,7 @@ namespace TEAMModelBI.Controllers.BISchool
                 {
                 {
                     schoolAssists = itemSchool;
                     schoolAssists = itemSchool;
                 }
                 }
-
+                //IES5實體學校
                 if (schoolAssists.id != null)
                 if (schoolAssists.id != null)
                 {
                 {
                     var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(schoolAssists.id, new PartitionKey("ProductSum"));
                     var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(schoolAssists.id, new PartitionKey("ProductSum"));
@@ -378,8 +395,16 @@ namespace TEAMModelBI.Controllers.BISchool
 
 
                     return Ok(new { state = 200, schoolAssists });
                     return Ok(new { state = 200, schoolAssists });
                 }
                 }
-                else return Ok(new { state = 404, msg = "未找到该学校!" });
-
+                //無實體學校 => 取得虛擬學校
+                else
+                {
+                    await foreach (var itemSchool in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<AssistSchool>(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("VirtualBase") }))
+                    {
+                        schoolAssists = itemSchool;
+                    }
+                    if (schoolAssists.id != null) return Ok(new { state = 200, schoolAssists });
+                    else return Ok(new { state = 404, msg = "未找到该学校!" });
+                }
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {
@@ -1033,6 +1058,14 @@ namespace TEAMModelBI.Controllers.BISchool
                 var cosmosClient = _azureCosmos.GetCosmosClient();
                 var cosmosClient = _azureCosmos.GetCosmosClient();
                 var tableClient = _azureStorage.GetCloudTableClient();
                 var tableClient = _azureStorage.GetCloudTableClient();
                 var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
                 var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
+                List<string> codes = (jsonElement.TryGetProperty("code", out JsonElement codeJobj)) ? codeJobj.ToObject<List<string>>() : new List<string>();
+                if (schools.Count > 0 && codes.Count.Equals(0)) //分區鍵值初始化
+                {
+                    for (int i = 0; i < schools.Count; i++)
+                    {
+                        codes.Add("Base");
+                    }
+                }
                 ////分开部署,就不需要,一站多用时,取消注释
                 ////分开部署,就不需要,一站多用时,取消注释
                 //if ($"{site}".Equals(BIConst.Global))
                 //if ($"{site}".Equals(BIConst.Global))
                 //{
                 //{
@@ -1045,66 +1078,81 @@ namespace TEAMModelBI.Controllers.BISchool
 
 
                 foreach (var tempId in schools)
                 foreach (var tempId in schools)
                 {
                 {
-                    List<string> scTchIds = new();
-                    List<string> scStuIds = new();
-                    string scTecSql = $"select value(c.id) from c where ARRAY_LENGTH(c.roles) > 0 and c.status = 'join'";
-                    await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: scTecSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{tempId}") }))
+                    int index = schools.IndexOf(tempId);
+                    string code = codes[index];
+                    //IES5實體學校刪除
+                    if (!code.Equals("VirtualBase"))
                     {
                     {
-                        scTchIds.Add(item);
-                    }
-
-                    string scStuSql = $"select value(c.id) from c";
-                    await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<string>(queryText: scStuSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{tempId}") }))
-                    {
-                        scStuIds.Add(item);
-                    }
+                        List<string> scTchIds = new();
+                        List<string> scStuIds = new();
+                        string scTecSql = $"select value(c.id) from c where ARRAY_LENGTH(c.roles) > 0 and c.status = 'join'";
+                        await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: scTecSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{tempId}") }))
+                        {
+                            scTchIds.Add(item);
+                        }
 
 
-                    var response = await cosmosClient.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync($"{tempId}", new PartitionKey($"Base"));
-                    if (response.Status == 204)
-                        msg.AppendLine($"{tmdName}【{tmdId}】删除学校,删除状态:{response.Status},删除ID:{tempId}");
-                    else
-                        delSchoolRels.Add(new DelSchoolRel() { id = $"{tempId}", code = "Base", type = 1, status = response.Status });
+                        string scStuSql = $"select value(c.id) from c";
+                        await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<string>(queryText: scStuSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{tempId}") }))
+                        {
+                            scStuIds.Add(item);
+                        }
 
 
-                    //删除学校信息中间
-                    var resBiRel = await cosmosClient.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync($"{tempId}", new PartitionKey($"BIRel"));
-                    if (resBiRel.Status == 204)
-                        msg.AppendLine($"{tmdName}【{tmdId}】删除学校信息中间件,删除状态:{resBiRel.Status},删除ID:{tempId}");
-                    else
-                        delSchoolRels.Add(new DelSchoolRel() { id = $"{tempId}", code = "Base", type = 1, status = response.Status });
+                        var response = await cosmosClient.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync($"{tempId}", new PartitionKey($"Base"));
+                        if (response.Status == 204)
+                            msg.AppendLine($"{tmdName}【{tmdId}】删除学校,删除状态:{response.Status},删除ID:{tempId}");
+                        else
+                            delSchoolRels.Add(new DelSchoolRel() { id = $"{tempId}", code = "Base", type = 1, status = response.Status });
 
 
-                    foreach (var item in scTchIds)
-                    {
-                        //学校教师信息
-                        var tchRespnse = await cosmosClient.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync($"{item}", new PartitionKey($"Teacher-{tempId}"));
-                        if (tchRespnse.Status == 204)
-                            msg.AppendLine($"删除教师,删除状态:{tchRespnse.Status},删除ID:{item}");
+                        //删除学校信息中间
+                        var resBiRel = await cosmosClient.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync($"{tempId}", new PartitionKey($"BIRel"));
+                        if (resBiRel.Status == 204)
+                            msg.AppendLine($"{tmdName}【{tmdId}】删除学校信息中间件,删除状态:{resBiRel.Status},删除ID:{tempId}");
                         else
                         else
-                            delSchoolRels.Add(new DelSchoolRel() { id = $"{item}", code = $"Teacher-{tempId}", type = 2, status = response.Status });
+                            delSchoolRels.Add(new DelSchoolRel() { id = $"{tempId}", code = "Base", type = 1, status = response.Status });
 
 
-                        //教师基础信息
-                        var tchBaseResponse = await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync($"{item}", new PartitionKey("Base"));
-                        if (tchBaseResponse.Status == 200)
+                        foreach (var item in scTchIds)
                         {
                         {
-                            using var json = await JsonDocument.ParseAsync(tchBaseResponse.ContentStream);
-                            Teacher teacher = json.ToObject<Teacher>();
-                            var tempSc = teacher.schools.Find(f => f.schoolId.Equals($"{tempId}"));
-                            if (tempSc != null)
+                            //学校教师信息
+                            var tchRespnse = await cosmosClient.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync($"{item}", new PartitionKey($"Teacher-{tempId}"));
+                            if (tchRespnse.Status == 204)
+                                msg.AppendLine($"删除教师,删除状态:{tchRespnse.Status},删除ID:{item}");
+                            else
+                                delSchoolRels.Add(new DelSchoolRel() { id = $"{item}", code = $"Teacher-{tempId}", type = 2, status = response.Status });
+
+                            //教师基础信息
+                            var tchBaseResponse = await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync($"{item}", new PartitionKey("Base"));
+                            if (tchBaseResponse.Status == 200)
                             {
                             {
-                                teacher.schools.Remove(tempSc);
-                                await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
+                                using var json = await JsonDocument.ParseAsync(tchBaseResponse.ContentStream);
+                                Teacher teacher = json.ToObject<Teacher>();
+                                var tempSc = teacher.schools.Find(f => f.schoolId.Equals($"{tempId}"));
+                                if (tempSc != null)
+                                {
+                                    teacher.schools.Remove(tempSc);
+                                    await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
+                                }
                             }
                             }
+                            else
+                                delSchoolRels.Add(new DelSchoolRel { id = $"{item}", code = "Base", type = 2, status = response.Status });
+                        }
+                        //删除学校学生
+                        foreach (var item in scStuIds)
+                        {
+                            var stuRespnse = await cosmosClient.GetContainer("TEAMModelOS", "Student").DeleteItemStreamAsync($"{item}", new PartitionKey($"Base-{tempId}"));
+                            if (stuRespnse.Status == 204)
+                                msg.AppendLine($"删除学生,删除状态:{stuRespnse.Status},删除ID:{item}");
+                            else
+                                delSchoolRels.Add(new DelSchoolRel() { id = $"{item}", code = $"Base-{tempId}", type = 3, status = response.Status });
                         }
                         }
-                        else
-                            delSchoolRels.Add(new DelSchoolRel { id = $"{item}", code = "Base", type = 2, status = response.Status });
                     }
                     }
-                    //删除学校学生
-                    foreach (var item in scStuIds)
+                    //虛擬學校刪除
+                    else
                     {
                     {
-                        var stuRespnse = await cosmosClient.GetContainer("TEAMModelOS", "Student").DeleteItemStreamAsync($"{item}", new PartitionKey($"Base-{tempId}"));
-                        if (stuRespnse.Status == 204)
-                            msg.AppendLine($"删除学生,删除状态:{stuRespnse.Status},删除ID:{item}");
+                        var response = await cosmosClient.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync($"{tempId}", new PartitionKey($"VirtualBase"));
+                        if (response.Status == 204)
+                            msg.AppendLine($"{tmdName}【{tmdId}】删除学校,删除状态:{response.Status},删除ID:{tempId}");
                         else
                         else
-                            delSchoolRels.Add(new DelSchoolRel() { id = $"{item}", code = $"Base-{tempId}", type = 3, status = response.Status });
+                            delSchoolRels.Add(new DelSchoolRel() { id = $"{tempId}", code = "VirtualBase", type = 1, status = response.Status });
                     }
                     }
                 }
                 }
 
 
@@ -2388,6 +2436,7 @@ namespace TEAMModelBI.Controllers.BISchool
         /// </summary>
         /// </summary>
         public record NotAreaSchool
         public record NotAreaSchool
         {
         {
+            public string code { get; set; }
             public string id { get; set; }
             public string id { get; set; }
             public string name { get; set; }
             public string name { get; set; }
             public string schoolCode { get; set; }
             public string schoolCode { get; set; }

+ 10 - 10
TEAMModelBI/Controllers/Census/SchoolController.cs

@@ -1414,16 +1414,16 @@ namespace TEAMModelBI.Controllers.Census
                 scInfos.Add(item);
                 scInfos.Add(item);
             }
             }
 
 
-            //虛擬學校 [需與學校修正做配套,先封印]
-            //StringBuilder sqlV = new($"select value(c) from c");
-            //if (!string.IsNullOrEmpty($"{areaId}") && !string.IsNullOrEmpty($"{role}"))
-            //{
-            //    sqlV.Append($" where c.areaId ='{areaId}'");
-            //}
-            //await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<BIRelation>(queryText: sqlV.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("VirtualBase") }))
-            //{
-            //    scInfos.Add(item);
-            //}
+            //虛擬學校
+            StringBuilder sqlV = new($"select value(c) from c");
+            if (!string.IsNullOrEmpty($"{areaId}") && !string.IsNullOrEmpty($"{role}"))
+            {
+                sqlV.Append($" where c.areaId ='{areaId}'");
+            }
+            await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<BIRelation>(queryText: sqlV.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("VirtualBase") }))
+            {
+                scInfos.Add(item);
+            }
 
 
             return Ok(new { state = RespondCode.Ok, allCnt = scInfos.Count, scInfos });
             return Ok(new { state = RespondCode.Ok, allCnt = scInfos.Count, scInfos });
         }
         }

+ 8 - 0
TEAMModelOS.SDK/Models/Cosmos/School/School.cs

@@ -163,4 +163,12 @@ namespace TEAMModelOS.SDK.Models
         /// </summary>
         /// </summary>
         public int record { get; set; } = 1;
         public int record { get; set; } = 1;
     }
     }
+
+    /// <summary>
+    /// 虛擬學校
+    /// </summary>
+    public class VirtualBase : School
+    {
+        public string areaName { get; set; }
+    } 
 }
 }

+ 2 - 2
TEAMModelOS.SDK/Models/Service/BI/BIProdAnalysis.cs

@@ -607,7 +607,7 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                             {
                             {
                                 foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
                                 foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
                                 {
                                 {
-                                    School crtVSchool = new School();
+                                    VirtualBase crtVSchool = new VirtualBase();
                                     crtVSchool.code = "VirtualBase";
                                     crtVSchool.code = "VirtualBase";
                                     crtVSchool.id = obj.GetProperty("shortCode").GetString();
                                     crtVSchool.id = obj.GetProperty("shortCode").GetString();
                                     crtVSchool.pk = "School";
                                     crtVSchool.pk = "School";
@@ -619,7 +619,7 @@ namespace TEAMModelOS.SDK.Models.Service.BI
                                     crtVSchool.dist = (obj.TryGetProperty("distName", out JsonElement distNameJ)) ? Convert.ToString(distNameJ) : null;
                                     crtVSchool.dist = (obj.TryGetProperty("distName", out JsonElement distNameJ)) ? Convert.ToString(distNameJ) : null;
                                     crtVSchool.address = (obj.TryGetProperty("address", out JsonElement addressJ)) ? Convert.ToString(addressJ) : null;
                                     crtVSchool.address = (obj.TryGetProperty("address", out JsonElement addressJ)) ? Convert.ToString(addressJ) : null;
                                     crtVSchool.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
                                     crtVSchool.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
-                                    await _azureCosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<School>(crtVSchool);
+                                    await _azureCosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<VirtualBase>(crtVSchool);
                                 }
                                 }
                             }
                             }
                         }
                         }

+ 44 - 38
TEAMModelOS.SDK/Models/Service/BI/BISchoolService.cs

@@ -19,47 +19,12 @@ namespace TEAMModelOS.SDK.Models.Service.BI
         /// <param name="server"></param>
         /// <param name="server"></param>
         /// <param name="id"></param>
         /// <param name="id"></param>
         /// <returns></returns>
         /// <returns></returns>
-        public static async Task UpSchoolEdition(CosmosClient cosmosClient,  DingDing _dingDing, List<string> server, string id)
+        public static async Task UpSchoolEdition(CosmosClient cosmosClient,  DingDing _dingDing, List<string> services, string id)
         {
         {
             try
             try
             {
             {
                 School school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(id, new PartitionKey("Base"));
                 School school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(id, new PartitionKey("Base"));
-                int edition = 0;
-                if (school.size <= 100 && school.scale == 0)
-                {
-                    edition = 1; 
-                }
-                else if (school.size >= 300 && school.scale >= 500 && school.scale<100 && server.Contains("YMPCVCIM"))
-                { 
-                    edition = 2;
-                }
-                else if (school.size >= 300 && school.scale >= 1000 && server.Contains("YMPCVCIM") && server.Count > 2)
-                { 
-                    edition = 3; 
-                }
-
-                if (edition == 0)
-                {
-                    edition = 1;
-                }
-                if (school.edition != null)
-                {
-                    school.edition.current = edition;
-                    if (school.edition.record < edition)
-                    {
-                        school.edition.record = edition;
-                    }
-                }
-                else
-                {
-                    Edition tempEdition = new()
-                    {
-                        current = edition,
-                        record = edition
-                    };
-
-                    school.edition = tempEdition;
-                }
+                school.edition = calSchoolEdition(school, services);
                 await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(school, id, new PartitionKey("Base"));
                 await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(school, id, new PartitionKey("Base"));
                 BIRelation biRel = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<BIRelation>(id, new PartitionKey("BIRel"));
                 BIRelation biRel = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<BIRelation>(id, new PartitionKey("BIRel"));
                 biRel.edition = school.edition;
                 biRel.edition = school.edition;
@@ -67,10 +32,51 @@ namespace TEAMModelOS.SDK.Models.Service.BI
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {
-                _ = _dingDing.SendBotMsg($"BI,{Environment.GetEnvironmentVariable("Option:Location")},UpSchoolEdition() 服务列表:{server},学校id:{id}\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.成都开发測試群組);
+                _ = _dingDing.SendBotMsg($"BI,{Environment.GetEnvironmentVariable("Option:Location")},UpSchoolEdition() 服务列表:{services},学校id:{id}\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.成都开发測試群組);
             }
             }
         }
         }
+        /// <summary>
+        /// 計算學校版本公式
+        /// </summary>
+        public static Edition calSchoolEdition(School school, List<string> services)
+        {
+            int edition = 0;
+            if (school.size <= 100 && school.scale == 0)
+            {
+                edition = 1;
+            }
+            else if (school.size >= 300 && school.scale >= 500 && school.scale < 100 && services.Contains("YMPCVCIM"))
+            {
+                edition = 2;
+            }
+            else if (school.size >= 300 && school.scale >= 1000 && services.Contains("YMPCVCIM") && services.Count > 2)
+            {
+                edition = 3;
+            }
 
 
+            if (edition == 0)
+            {
+                edition = 1;
+            }
+            if (school.edition != null)
+            {
+                school.edition.current = edition;
+                if (school.edition.record < edition)
+                {
+                    school.edition.record = edition;
+                }
+            }
+            else
+            {
+                Edition tempEdition = new()
+                {
+                    current = edition,
+                    record = edition
+                };
 
 
+                school.edition = tempEdition;
+            }
+            return school.edition;
+        }
     }
     }
 }
 }