|
@@ -29,6 +29,12 @@ using TEAMModelBI.Models;
|
|
|
using TEAMModelOS.SDK;
|
|
|
using TEAMModelOS.SDK.Context.BI;
|
|
|
using TEAMModelOS.SDK.Context.Constant;
|
|
|
+using Pipelines.Sockets.Unofficial.Arenas;
|
|
|
+using Microsoft.Identity.Client;
|
|
|
+using TEAMModelOS.SDK.Models.Dtos;
|
|
|
+using static TEAMModelBI.Controllers.BITest.TestController;
|
|
|
+using static TEAMModelBI.Controllers.BISchool.BatchSchoolController;
|
|
|
+using DocumentFormat.OpenXml.Spreadsheet;
|
|
|
|
|
|
namespace TEAMModelBI.Controllers.BISchool
|
|
|
{
|
|
@@ -100,24 +106,19 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
|
var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
var tableClient = _azureStorage.GetCloudTableClient();
|
|
|
var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
|
|
|
- if (BIConst.Global.Equals($"{foundSchools.site}"))
|
|
|
- {
|
|
|
- cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
|
|
|
- tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
|
|
|
- blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
|
|
|
- }
|
|
|
+ //if (BIConst.Global.Equals($"{foundSchools.site}"))
|
|
|
+ //{
|
|
|
+ // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
|
|
|
+ // tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
|
|
|
+ // blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
|
|
|
+ //}
|
|
|
|
|
|
if (foundSchools.biSchools.Count > 0)
|
|
|
{
|
|
|
+ #region 新版直接创建
|
|
|
+
|
|
|
foreach (BISchool bischool in foundSchools.biSchools)
|
|
|
{
|
|
|
- List<string> scName = new();
|
|
|
- //查询学校名称是否全字段匹配
|
|
|
- await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: $"select value(c.name) from c where c.name='{bischool.name}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
|
|
|
- {
|
|
|
- scName.Add(item);
|
|
|
- }
|
|
|
-
|
|
|
Area area = null;
|
|
|
//查询区是否存在
|
|
|
var respAreaId = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{bischool.areaId}", new PartitionKey("Base-Area"));
|
|
@@ -127,150 +128,303 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
|
area = areaBase.ToObject<Area>();
|
|
|
}
|
|
|
|
|
|
- bool isSYNCArea = false;
|
|
|
- //查询去是否同步省平台
|
|
|
- var responseSet = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{bischool.areaId}", new PartitionKey("AreaSetting"));
|
|
|
- if (responseSet.Status == 200)
|
|
|
+ CreateSchoolInfo createSchoolInfo = new CreateSchoolInfo()
|
|
|
{
|
|
|
- using var fileJson = await JsonDocument.ParseAsync(responseSet.ContentStream);
|
|
|
- AreaSetting delSet = fileJson.ToObject<AreaSetting>();
|
|
|
- if (!string.IsNullOrEmpty(delSet.accessConfig))
|
|
|
- isSYNCArea = true;
|
|
|
- }
|
|
|
-
|
|
|
- if (scName.Count <= 0)
|
|
|
+ province = bischool.province,
|
|
|
+ id = "",
|
|
|
+ name = bischool.name,
|
|
|
+ city = bischool.city,
|
|
|
+ aname = "",
|
|
|
+ createCount = 0,
|
|
|
+ };
|
|
|
+
|
|
|
+ //生成学校ID
|
|
|
+ bool tempStaus = true;
|
|
|
+ do
|
|
|
+ {
|
|
|
+ createSchoolInfo = await SchoolCode.GenerateSchoolCode(createSchoolInfo, _dingDing, _environment);
|
|
|
+ var schoolStatu = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{createSchoolInfo.id}", new PartitionKey($"Base"));
|
|
|
+ if (schoolStatu.Status != 200) tempStaus = false;
|
|
|
+ else createSchoolInfo.createCount = createSchoolInfo.createCount >= 3 ? createSchoolInfo.createCount = 3 : createSchoolInfo.createCount += 1;
|
|
|
+ } while (tempStaus);
|
|
|
+
|
|
|
+ if (createSchoolInfo.id != null)
|
|
|
{
|
|
|
- if (isSYNCArea == false)
|
|
|
+ string campusId = Guid.NewGuid().ToString();
|
|
|
+ School upSchool = new()
|
|
|
+ {
|
|
|
+ id = createSchoolInfo.id,
|
|
|
+ name = bischool.name,
|
|
|
+ size = bischool.size == 0 ? 100 : bischool.size,
|
|
|
+ code = "Base",
|
|
|
+ campuses = new List<Campus> { new Campus { name = bischool.name, id = campusId } },
|
|
|
+ region = bischool.region,
|
|
|
+ province = bischool.province,
|
|
|
+ city = bischool.city,
|
|
|
+ dist = bischool.dist,
|
|
|
+ address = bischool.address,
|
|
|
+ picture = "https://teammodelstorage.blob.core.chinacloudapi.cn/0-public/school/bbf54fb3-3fc8-43ae-a358-107281c174cc.png",
|
|
|
+ timeZone = new TEAMModelOS.SDK.Models.TimeZone { label = "(UTC+08:00) 北京,重庆,香港特别行政区,乌鲁木齐", value = "+08:00" },
|
|
|
+ type = string.IsNullOrEmpty(bischool.type.ToString()) ? 1 : bischool.type,
|
|
|
+ pk = "School",
|
|
|
+ ttl = -1,
|
|
|
+ areaId = area == null ? "" : area.id,
|
|
|
+ standard = area == null ? "" : area.standard,
|
|
|
+ schoolCode = createSchoolInfo.id,
|
|
|
+ period = PresetSchoolPeriod(bischool.period, foundSchools.lang, campusId),
|
|
|
+ scale = bischool.size >= 300 ? 500 : 0,
|
|
|
+ createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
|
|
|
+ };
|
|
|
+
|
|
|
+ stringBuilder.Append($"创建学校:{upSchool.name}【{upSchool.id}】");
|
|
|
+ noticeDD.Append($"{upSchool.name}【{upSchool.id}】 \r 学校管理员信息:");
|
|
|
+ upSc.Add(upSchool.id);
|
|
|
+ //创建学校
|
|
|
+ await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<School>(upSchool, new PartitionKey(upSchool.code));
|
|
|
+
|
|
|
+ var content = new StringContent(bischool.admin.ToArray().ToJsonString(), Encoding.UTF8, "application/json");
|
|
|
+ string json = await _coreAPIHttpService.GetUserInfos(content);
|
|
|
+ List<TmdUserinfo> tmdInfos = json.ToObject<List<TmdUserinfo>>();
|
|
|
+
|
|
|
+ foreach (var tmdIndo in tmdInfos)
|
|
|
{
|
|
|
- var coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", $"{bischool.admin}" } }, _option.Location, _configuration);
|
|
|
- if (coreUser != null && coreUser.id != null)
|
|
|
+ Teacher teacher = new();
|
|
|
+ var resTeache = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemStreamAsync($"{tmdIndo.id}", new PartitionKey("Base"));
|
|
|
+ if (resTeache.Status == 200)
|
|
|
{
|
|
|
- CreateSchoolInfo createSchoolInfo = new CreateSchoolInfo()
|
|
|
+ using var tchJson = await JsonDocument.ParseAsync(resTeache.ContentStream);
|
|
|
+ teacher = tchJson.ToObject<Teacher>();
|
|
|
+ //教师存在,在该教师信息中添加要管理的学校信息
|
|
|
+ teacher.schools.Add(new Teacher.TeacherSchool { areaId = string.IsNullOrEmpty(bischool.areaId) ? "" : bischool.areaId, schoolId = createSchoolInfo.id, name = bischool.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() });
|
|
|
+ //await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, coreUser.id, new PartitionKey("Base"));
|
|
|
+ SchoolTeacher schoolTeacher = new()
|
|
|
{
|
|
|
- province = bischool.province,
|
|
|
- id = "",
|
|
|
- name = bischool.name,
|
|
|
- city = bischool.city,
|
|
|
- aname = "",
|
|
|
- createCount = 0,
|
|
|
+ id = tmdIndo.id,
|
|
|
+ code = $"Teacher-{createSchoolInfo.id}",
|
|
|
+ roles = new List<string> { "admin" },
|
|
|
+ job = "管理员",
|
|
|
+ name = teacher.name,
|
|
|
+ picture = teacher.picture,
|
|
|
+ status = "join",
|
|
|
+ createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
+ pk = "Teacher",
|
|
|
+ ttl = -1
|
|
|
};
|
|
|
-
|
|
|
- //生成学校ID
|
|
|
- bool tempStaus = true;
|
|
|
- do
|
|
|
+ stringBuilder.Append($"【基础:{schoolTeacher.name}【{schoolTeacher.id}】,权限:{string.Join(",", schoolTeacher.roles)}】");
|
|
|
+ noticeDD.Append($"{schoolTeacher.name}【{schoolTeacher.id}】");
|
|
|
+ await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
|
|
|
+ await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey(schoolTeacher.code));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //不存在 新建教师和新建要管理的学校信息
|
|
|
+ Teacher addteacher = new()
|
|
|
{
|
|
|
- createSchoolInfo = await SchoolCode.GenerateSchoolCode(createSchoolInfo, _dingDing, _environment);
|
|
|
- var schoolStatu = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{createSchoolInfo.id}", new PartitionKey($"Base"));
|
|
|
- if (schoolStatu.Status != 200) tempStaus = false;
|
|
|
- else createSchoolInfo.createCount = createSchoolInfo.createCount >= 3 ? createSchoolInfo.createCount = 3 : createSchoolInfo.createCount += 1;
|
|
|
- } while (tempStaus);
|
|
|
+ id = tmdIndo.id,
|
|
|
+ pk = "Base",
|
|
|
+ code = "Base",
|
|
|
+ name = $"{tmdIndo.name}",
|
|
|
+ picture = $"{tmdIndo.picture}",
|
|
|
+ //创建账号并第一次登录IES5则默认赠送1G
|
|
|
+ size = 1,
|
|
|
+ defaultSchool = createSchoolInfo.id,
|
|
|
+ createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
+ schools = new List<Teacher.TeacherSchool>() { new Teacher.TeacherSchool { schoolId = createSchoolInfo.id, name = bischool.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() } }
|
|
|
+ };
|
|
|
|
|
|
- if (createSchoolInfo.id != null)
|
|
|
- {
|
|
|
- string campusId = Guid.NewGuid().ToString();
|
|
|
- School upSchool = new()
|
|
|
- {
|
|
|
- id = createSchoolInfo.id,
|
|
|
- name = bischool.name,
|
|
|
- size = bischool.size == 0 ? 100 : bischool.size,
|
|
|
- code = "Base",
|
|
|
- campuses = new List<Campus> { new Campus { name = bischool.name, id = campusId } },
|
|
|
- region = bischool.region,
|
|
|
- province = bischool.province,
|
|
|
- city = bischool.city,
|
|
|
- dist = bischool.dist,
|
|
|
- address = bischool.address,
|
|
|
- picture = "https://teammodelstorage.blob.core.chinacloudapi.cn/0-public/school/bbf54fb3-3fc8-43ae-a358-107281c174cc.png",
|
|
|
- timeZone = new TEAMModelOS.SDK.Models.TimeZone { label = "(UTC+08:00) 北京,重庆,香港特别行政区,乌鲁木齐", value = "+08:00" },
|
|
|
- type = string.IsNullOrEmpty(bischool.type.ToString()) ? 1 : bischool.type,
|
|
|
- pk = "School",
|
|
|
- ttl = -1,
|
|
|
- areaId = area == null ? "" : area.id,
|
|
|
- standard = area == null ? "" : area.standard,
|
|
|
- schoolCode = createSchoolInfo.id,
|
|
|
- period = PresetSchoolPeriod(bischool.period, foundSchools.lang, campusId),
|
|
|
- scale = bischool.size >= 300 ? 500 : 0,
|
|
|
- createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
|
|
|
- };
|
|
|
+ stringBuilder.Append($"【没有该教师基础信息,创建的教师基本信息:{addteacher.name}【{addteacher.id}】");
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(addteacher, new PartitionKey("Base"));
|
|
|
|
|
|
- stringBuilder.Append($"创建学校:{upSchool.name}【{upSchool.id}】");
|
|
|
- noticeDD.Append($"【ID:{upSchool.id}|名称:{upSchool.name}】 ");
|
|
|
- upSc.Add(upSchool.id);
|
|
|
- //创建学校
|
|
|
- await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<School>(upSchool, new PartitionKey(upSchool.code));
|
|
|
+ SchoolTeacher schoolTeacher = new()
|
|
|
+ {
|
|
|
+ id = tmdIndo.id,
|
|
|
+ code = $"Teacher-{createSchoolInfo.id}",
|
|
|
+ roles = new List<string> { "admin" },
|
|
|
+ job = "管理员",
|
|
|
+ name = $"{tmdIndo.name}",
|
|
|
+ picture = "",
|
|
|
+ status = "join",
|
|
|
+ createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
+ pk = "Teacher",
|
|
|
+ ttl = -1
|
|
|
+ };
|
|
|
|
|
|
- //创建学校管理员
|
|
|
- Teacher teacher = null;
|
|
|
- var resTeache = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemStreamAsync($"{coreUser.id}", new PartitionKey("Base"));
|
|
|
- if (resTeache.Status == 200)
|
|
|
- {
|
|
|
- using var tchJson = await JsonDocument.ParseAsync(resTeache.ContentStream);
|
|
|
- teacher = tchJson.ToObject<Teacher>();
|
|
|
- //教师存在,在该教师信息中添加要管理的学校信息
|
|
|
- teacher.schools.Add(new Teacher.TeacherSchool { areaId = string.IsNullOrEmpty(bischool.areaId) ? "" : bischool.areaId, schoolId = createSchoolInfo.id, name = bischool.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() });
|
|
|
- //await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, coreUser.id, new PartitionKey("Base"));
|
|
|
- SchoolTeacher schoolTeacher = new()
|
|
|
- {
|
|
|
- id = coreUser.id,
|
|
|
- code = $"Teacher-{createSchoolInfo.id}",
|
|
|
- roles = new List<string> { "admin", "teacher" },
|
|
|
- job = "管理员",
|
|
|
- name = teacher.name,
|
|
|
- picture = teacher.picture,
|
|
|
- status = "join",
|
|
|
- createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
- pk = "Teacher",
|
|
|
- ttl = -1
|
|
|
- };
|
|
|
- stringBuilder.Append($"教师信息:{schoolTeacher.name}【{schoolTeacher.id}】,教师权限:{string.Join(",", schoolTeacher.roles)}");
|
|
|
- await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
|
|
|
- await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey(schoolTeacher.code));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //不存在 新建教师和新建要管理的学校信息
|
|
|
- Teacher addteacher = new()
|
|
|
- {
|
|
|
- id = coreUser.id,
|
|
|
- pk = "Base",
|
|
|
- code = "Base",
|
|
|
- name = $"{coreUser.name}",
|
|
|
- picture = $"{coreUser.picture}",
|
|
|
- //创建账号并第一次登录IES5则默认赠送1G
|
|
|
- size = 1,
|
|
|
- defaultSchool = createSchoolInfo.id,
|
|
|
- createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
- schools = new List<Teacher.TeacherSchool>() { new Teacher.TeacherSchool { schoolId = createSchoolInfo.id, name = bischool.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() } }
|
|
|
- };
|
|
|
-
|
|
|
- stringBuilder.Append($"没有该教师信息创建的教师信息:{addteacher.name}【{addteacher.id}】");
|
|
|
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(addteacher, new PartitionKey("Base"));
|
|
|
-
|
|
|
- SchoolTeacher schoolTeacher = new()
|
|
|
- {
|
|
|
- id = coreUser.id,
|
|
|
- code = $"Teacher-{createSchoolInfo.id}",
|
|
|
- roles = new List<string> { "admin", "teacher" },
|
|
|
- job = "管理员",
|
|
|
- name = $"{coreUser.name}",
|
|
|
- picture = "",
|
|
|
- status = "join",
|
|
|
- createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
- pk = "Teacher",
|
|
|
- ttl = -1
|
|
|
- };
|
|
|
-
|
|
|
- stringBuilder.Append($"教师权限:{string.Join(",", schoolTeacher.roles)}");
|
|
|
- await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey(schoolTeacher.code));
|
|
|
- }
|
|
|
- }
|
|
|
+ stringBuilder.Append($"权限:{string.Join(",", schoolTeacher.roles)}】");
|
|
|
+ noticeDD.Append($"{schoolTeacher.name}【{schoolTeacher.id}】");
|
|
|
+ await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey(schoolTeacher.code));
|
|
|
}
|
|
|
- else userScs.Add(bischool);
|
|
|
}
|
|
|
- else cutArea.Add(bischool);
|
|
|
}
|
|
|
- else schools.Add(bischool);
|
|
|
}
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 旧版先检测 在创建
|
|
|
+
|
|
|
+ //foreach (BISchool bischool in foundSchools.biSchools)
|
|
|
+ //{
|
|
|
+ // List<string> scName = new();
|
|
|
+ // //查询学校名称是否全字段匹配
|
|
|
+ // await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: $"select value(c.name) from c where c.name='{bischool.name}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
|
|
|
+ // {
|
|
|
+ // scName.Add(item);
|
|
|
+ // }
|
|
|
+
|
|
|
+ // Area area = null;
|
|
|
+ // //查询区是否存在
|
|
|
+ // var respAreaId = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{bischool.areaId}", new PartitionKey("Base-Area"));
|
|
|
+ // if (respAreaId.Status == 200)
|
|
|
+ // {
|
|
|
+ // using var areaBase = await JsonDocument.ParseAsync(respAreaId.ContentStream);
|
|
|
+ // area = areaBase.ToObject<Area>();
|
|
|
+ // }
|
|
|
+
|
|
|
+ // bool isSYNCArea = false;
|
|
|
+ // //查询去是否同步省平台
|
|
|
+ // var responseSet = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{bischool.areaId}", new PartitionKey("AreaSetting"));
|
|
|
+ // if (responseSet.Status == 200)
|
|
|
+ // {
|
|
|
+ // using var fileJson = await JsonDocument.ParseAsync(responseSet.ContentStream);
|
|
|
+ // AreaSetting delSet = fileJson.ToObject<AreaSetting>();
|
|
|
+ // if (!string.IsNullOrEmpty(delSet.accessConfig))
|
|
|
+ // isSYNCArea = true;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // if (scName.Count <= 0)
|
|
|
+ // {
|
|
|
+ // if (isSYNCArea == false)
|
|
|
+ // {
|
|
|
+ // var coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", $"{bischool.admin}" } }, _option.Location, _configuration);
|
|
|
+ // if (coreUser != null && coreUser.id != null)
|
|
|
+ // {
|
|
|
+ // CreateSchoolInfo createSchoolInfo = new CreateSchoolInfo()
|
|
|
+ // {
|
|
|
+ // province = bischool.province,
|
|
|
+ // id = "",
|
|
|
+ // name = bischool.name,
|
|
|
+ // city = bischool.city,
|
|
|
+ // aname = "",
|
|
|
+ // createCount = 0,
|
|
|
+ // };
|
|
|
+
|
|
|
+ // //生成学校ID
|
|
|
+ // bool tempStaus = true;
|
|
|
+ // do
|
|
|
+ // {
|
|
|
+ // createSchoolInfo = await SchoolCode.GenerateSchoolCode(createSchoolInfo, _dingDing, _environment);
|
|
|
+ // var schoolStatu = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{createSchoolInfo.id}", new PartitionKey($"Base"));
|
|
|
+ // if (schoolStatu.Status != 200) tempStaus = false;
|
|
|
+ // else createSchoolInfo.createCount = createSchoolInfo.createCount >= 3 ? createSchoolInfo.createCount = 3 : createSchoolInfo.createCount += 1;
|
|
|
+ // } while (tempStaus);
|
|
|
+
|
|
|
+ // if (createSchoolInfo.id != null)
|
|
|
+ // {
|
|
|
+ // string campusId = Guid.NewGuid().ToString();
|
|
|
+ // School upSchool = new()
|
|
|
+ // {
|
|
|
+ // id = createSchoolInfo.id,
|
|
|
+ // name = bischool.name,
|
|
|
+ // size = bischool.size == 0 ? 100 : bischool.size,
|
|
|
+ // code = "Base",
|
|
|
+ // campuses = new List<Campus> { new Campus { name = bischool.name, id = campusId } },
|
|
|
+ // region = bischool.region,
|
|
|
+ // province = bischool.province,
|
|
|
+ // city = bischool.city,
|
|
|
+ // dist = bischool.dist,
|
|
|
+ // address = bischool.address,
|
|
|
+ // picture = "https://teammodelstorage.blob.core.chinacloudapi.cn/0-public/school/bbf54fb3-3fc8-43ae-a358-107281c174cc.png",
|
|
|
+ // timeZone = new TEAMModelOS.SDK.Models.TimeZone { label = "(UTC+08:00) 北京,重庆,香港特别行政区,乌鲁木齐", value = "+08:00" },
|
|
|
+ // type = string.IsNullOrEmpty(bischool.type.ToString()) ? 1 : bischool.type,
|
|
|
+ // pk = "School",
|
|
|
+ // ttl = -1,
|
|
|
+ // areaId = area == null ? "" : area.id,
|
|
|
+ // standard = area == null ? "" : area.standard,
|
|
|
+ // schoolCode = createSchoolInfo.id,
|
|
|
+ // period = PresetSchoolPeriod(bischool.period, foundSchools.lang, campusId),
|
|
|
+ // scale = bischool.size >= 300 ? 500 : 0,
|
|
|
+ // createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
|
|
|
+ // };
|
|
|
+
|
|
|
+ // stringBuilder.Append($"创建学校:{upSchool.name}【{upSchool.id}】");
|
|
|
+ // noticeDD.Append($"【ID:{upSchool.id}|名称:{upSchool.name}】 ");
|
|
|
+ // upSc.Add(upSchool.id);
|
|
|
+ // //创建学校
|
|
|
+ // await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<School>(upSchool, new PartitionKey(upSchool.code));
|
|
|
+
|
|
|
+ // //创建学校管理员
|
|
|
+ // Teacher teacher = null;
|
|
|
+ // var resTeache = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemStreamAsync($"{coreUser.id}", new PartitionKey("Base"));
|
|
|
+ // if (resTeache.Status == 200)
|
|
|
+ // {
|
|
|
+ // using var tchJson = await JsonDocument.ParseAsync(resTeache.ContentStream);
|
|
|
+ // teacher = tchJson.ToObject<Teacher>();
|
|
|
+ // //教师存在,在该教师信息中添加要管理的学校信息
|
|
|
+ // teacher.schools.Add(new Teacher.TeacherSchool { areaId = string.IsNullOrEmpty(bischool.areaId) ? "" : bischool.areaId, schoolId = createSchoolInfo.id, name = bischool.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() });
|
|
|
+ // //await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, coreUser.id, new PartitionKey("Base"));
|
|
|
+ // SchoolTeacher schoolTeacher = new()
|
|
|
+ // {
|
|
|
+ // id = coreUser.id,
|
|
|
+ // code = $"Teacher-{createSchoolInfo.id}",
|
|
|
+ // roles = new List<string> { "admin", "teacher" },
|
|
|
+ // job = "管理员",
|
|
|
+ // name = teacher.name,
|
|
|
+ // picture = teacher.picture,
|
|
|
+ // status = "join",
|
|
|
+ // createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
+ // pk = "Teacher",
|
|
|
+ // ttl = -1
|
|
|
+ // };
|
|
|
+ // stringBuilder.Append($"教师信息:{schoolTeacher.name}【{schoolTeacher.id}】,教师权限:{string.Join(",", schoolTeacher.roles)}");
|
|
|
+ // await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
|
|
|
+ // await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey(schoolTeacher.code));
|
|
|
+ // }
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // //不存在 新建教师和新建要管理的学校信息
|
|
|
+ // Teacher addteacher = new()
|
|
|
+ // {
|
|
|
+ // id = coreUser.id,
|
|
|
+ // pk = "Base",
|
|
|
+ // code = "Base",
|
|
|
+ // name = $"{coreUser.name}",
|
|
|
+ // picture = $"{coreUser.picture}",
|
|
|
+ // //创建账号并第一次登录IES5则默认赠送1G
|
|
|
+ // size = 1,
|
|
|
+ // defaultSchool = createSchoolInfo.id,
|
|
|
+ // createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
+ // schools = new List<Teacher.TeacherSchool>() { new Teacher.TeacherSchool { schoolId = createSchoolInfo.id, name = bischool.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() } }
|
|
|
+ // };
|
|
|
+
|
|
|
+ // stringBuilder.Append($"没有该教师信息创建的教师信息:{addteacher.name}【{addteacher.id}】");
|
|
|
+ // await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(addteacher, new PartitionKey("Base"));
|
|
|
+
|
|
|
+ // SchoolTeacher schoolTeacher = new()
|
|
|
+ // {
|
|
|
+ // id = coreUser.id,
|
|
|
+ // code = $"Teacher-{createSchoolInfo.id}",
|
|
|
+ // roles = new List<string> { "admin", "teacher" },
|
|
|
+ // job = "管理员",
|
|
|
+ // name = $"{coreUser.name}",
|
|
|
+ // picture = "",
|
|
|
+ // status = "join",
|
|
|
+ // createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
+ // pk = "Teacher",
|
|
|
+ // ttl = -1
|
|
|
+ // };
|
|
|
+
|
|
|
+ // stringBuilder.Append($"教师权限:{string.Join(",", schoolTeacher.roles)}");
|
|
|
+ // await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey(schoolTeacher.code));
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // else userScs.Add(bischool);
|
|
|
+ // }
|
|
|
+ // else cutArea.Add(bischool);
|
|
|
+ // }
|
|
|
+ // else schools.Add(bischool);
|
|
|
+ //}
|
|
|
+
|
|
|
+ #endregion
|
|
|
}
|
|
|
else return Ok(new { state = 1, message = "创校信息为空" });
|
|
|
|
|
@@ -832,6 +986,7 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
|
/// </summary>
|
|
|
/// <param name="jsonElement"></param>
|
|
|
/// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
[HttpPost("get-schools")]
|
|
|
public async Task<IActionResult> GetSchools(JsonElement jsonElement)
|
|
|
{
|
|
@@ -875,6 +1030,194 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
|
return Ok(new { state = 200, schoolAssists });
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 创校前检查数据
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("get-checlkexist")]
|
|
|
+ public async Task<IActionResult> GetCheckExist(JsonElement jsonElement)
|
|
|
+ {
|
|
|
+ if (!jsonElement.TryGetProperty("scNames", out JsonElement _scNames)) return BadRequest();
|
|
|
+ if (!jsonElement.TryGetProperty("accounts", out JsonElement _accounts)) return BadRequest();
|
|
|
+ if (!jsonElement.TryGetProperty("areaIds", out JsonElement _areaIds)) return BadRequest();
|
|
|
+
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
+
|
|
|
+ List<string> scNames = _scNames.ToObject<List<string>>();
|
|
|
+ List<string> accounts = _accounts.ToObject<List<string>>();
|
|
|
+ List<string> areaIds = _areaIds.ToObject<List<string>>();
|
|
|
+
|
|
|
+ List<string> existScNames = new(); //存在的学校
|
|
|
+ List<string> noAccounts = new(); // 不存在的账户
|
|
|
+ List<string> noAreaIds = new(); //不存在的学区
|
|
|
+ List<string> synPro = new(); //已同步省平台
|
|
|
+
|
|
|
+ if (scNames.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (var item in scNames)
|
|
|
+ {
|
|
|
+ //查询学校名称是否全字段匹配
|
|
|
+ await foreach (var sc in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: $"select value(c.name) from c where c.name='{item}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
|
|
|
+ {
|
|
|
+ existScNames.Add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (accounts.Count > 0)
|
|
|
+ {
|
|
|
+ var content = new StringContent(_accounts.ToString(), Encoding.UTF8, "application/json");
|
|
|
+ string json = await _coreAPIHttpService.GetUserInfos(content);
|
|
|
+ List<TmdUserinfo> tmdInfos = json.ToObject<List<TmdUserinfo>>();
|
|
|
+
|
|
|
+ accounts.ForEach(ac =>
|
|
|
+ {
|
|
|
+ var noTmdInfo = tmdInfos.Find(f => f.id.Equals($"{ac}") || f.mail.Equals($"{ac}") || f.mobile.Equals($"{ac}"));
|
|
|
+ if (noTmdInfo == null)
|
|
|
+ noAccounts.Add(ac);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if (areaIds.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (var item in areaIds)
|
|
|
+ {
|
|
|
+ //查询区是否存在
|
|
|
+ var respAreaId = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{item}", new PartitionKey("Base-Area"));
|
|
|
+ if (respAreaId.Status != 200)
|
|
|
+ {
|
|
|
+ noAreaIds.Add(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询去是否同步省平台
|
|
|
+ var responseSet = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{item}", new PartitionKey("AreaSetting"));
|
|
|
+ if (responseSet.Status == 200)
|
|
|
+ {
|
|
|
+ using var fileJson = await JsonDocument.ParseAsync(responseSet.ContentStream);
|
|
|
+ AreaSetting delSet = fileJson.ToObject<AreaSetting>();
|
|
|
+ if (!string.IsNullOrEmpty(delSet.accessConfig))
|
|
|
+ synPro.Add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (existScNames.Count > 0 || noAccounts.Count > 0 || noAreaIds.Count > 0 || synPro.Count > 0)
|
|
|
+ return Ok(new { state = RespondCode.Created, existScNames, noAccounts, noAreaIds, synPro });
|
|
|
+ else
|
|
|
+ return Ok(new { state = RespondCode.Ok });
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 添加多个学校添加多个管理员
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("set-batchmanage")]
|
|
|
+ public async Task<IActionResult> SetBatchManage(JsonElement jsonElement)
|
|
|
+ {
|
|
|
+ if (!jsonElement.TryGetProperty("scIds", out JsonElement _scIds)) return BadRequest();
|
|
|
+ if (!jsonElement.TryGetProperty("manages", out JsonElement _manages)) return BadRequest();
|
|
|
+
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
+
|
|
|
+ List<string> scIds= _scIds.ToObject<List<string>>();
|
|
|
+ List<string> manages = _manages.ToObject<List<string>>();
|
|
|
+
|
|
|
+ List<ExistScManage> existScManages = new();
|
|
|
+ if (scIds.Count > 0 && manages.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (var scId in scIds)
|
|
|
+ {
|
|
|
+ foreach (var msId in manages)
|
|
|
+ {
|
|
|
+ //不存在则在原来的基础上添加顾问角色
|
|
|
+ Teacher tempTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>($"{msId}", new PartitionKey("Base"));
|
|
|
+ if (tempTeacher != null)
|
|
|
+ {
|
|
|
+ var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{msId}", new PartitionKey($"Teacher-{scId}"));
|
|
|
+ if (response.Status == 200)
|
|
|
+ {
|
|
|
+ using var tchJson = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
+ SchoolTeacher tchSc = tchJson.ToObject<SchoolTeacher>();
|
|
|
+ if (tchSc.roles.Contains("admin"))
|
|
|
+ {
|
|
|
+ tchSc.roles.Add("admin");
|
|
|
+ //添加顾问权限
|
|
|
+ await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<SchoolTeacher>(tchSc, tchSc.id, new PartitionKey($"Teacher-{scId}"));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ existScManages.Add(new ExistScManage() { scId = scId, tmdId = msId });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ SchoolTeacher addSchoolTeacher = new()
|
|
|
+ {
|
|
|
+ id = tempTeacher.id,
|
|
|
+ code = $"Teacher-{scId}",
|
|
|
+ pk = "Teacher",
|
|
|
+ status = "join",
|
|
|
+ roles = new List<string>() { "admin" },
|
|
|
+ name = tempTeacher.name,
|
|
|
+ job = $"管理员",
|
|
|
+ size = 0,
|
|
|
+ createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
|
|
|
+ };
|
|
|
+
|
|
|
+ var haveTeacher = tempTeacher.schools.Find(x => x.schoolId.Equals($"{scId}"));
|
|
|
+ if (haveTeacher == null)
|
|
|
+ {
|
|
|
+ School school = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemAsync<School>(scId, new PartitionKey("Base"));
|
|
|
+ //教师存在,在该教师信息中添加要管理的学校信息
|
|
|
+ tempTeacher.schools.Add(new Teacher.TeacherSchool { areaId = string.IsNullOrEmpty(school.areaId) ? "" : school.areaId, schoolId = school.id, name = school.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() });
|
|
|
+
|
|
|
+ tempTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(tempTeacher, msId, new PartitionKey("Base"));
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加学校学校顾问
|
|
|
+ await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(addSchoolTeacher, new PartitionKey($"Teacher-{scId}"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ CoreUser coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", $"{msId}" } }, _option.Location, _configuration);
|
|
|
+
|
|
|
+ Teacher teacher = new() { id = coreUser.id, name = coreUser.name, picture = coreUser.picture, pk = "Base", code = "Base", size = 1, createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() };
|
|
|
+ var responseSc = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(scId, new PartitionKey("Base"));
|
|
|
+ if (responseSc.Status == 200)
|
|
|
+ {
|
|
|
+ using var tchJson = await JsonDocument.ParseAsync(responseSc.ContentStream);
|
|
|
+ School scInfo = tchJson.ToObject<School>();
|
|
|
+ teacher.schools.Add(new() { schoolId = scInfo.id, name = scInfo.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), picture = scInfo.picture, areaId = scInfo.areaId });
|
|
|
+ }
|
|
|
+
|
|
|
+ teacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey("Base"));
|
|
|
+ SchoolTeacher addSchoolTeacher = new()
|
|
|
+ {
|
|
|
+ id = coreUser.id,
|
|
|
+ code = $"Teacher-{scId}",
|
|
|
+ pk = "Teacher",
|
|
|
+ status = "join",
|
|
|
+ roles = new List<string>() { "admin" },
|
|
|
+ name = coreUser.name,
|
|
|
+ job = $"管理员",
|
|
|
+ size = 0,
|
|
|
+ createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
|
|
|
+ };
|
|
|
+
|
|
|
+ //添加学校学校顾问
|
|
|
+ await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(addSchoolTeacher, new PartitionKey($"Teacher-{scId}"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (existScManages.Count > 0)
|
|
|
+ return Ok(new { state = RespondCode.Created, existScManages });
|
|
|
+ else
|
|
|
+ return Ok(new { state = RespondCode.Ok });
|
|
|
+ }
|
|
|
|
|
|
#region 预设学校基础信息 多语言
|
|
|
|
|
@@ -1044,7 +1387,7 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
|
/// <summary>
|
|
|
/// 学校管理员
|
|
|
/// </summary>
|
|
|
- public string admin { get; set; }
|
|
|
+ public List<string> admin { get; set; }
|
|
|
/// <summary>
|
|
|
/// 学校的学段
|
|
|
/// </summary>
|
|
@@ -1087,10 +1430,11 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
|
public string standard { get; set; }
|
|
|
}
|
|
|
|
|
|
- public record Exist()
|
|
|
+
|
|
|
+ public record ExistScManage
|
|
|
{
|
|
|
- public string ID { get; set; }
|
|
|
- public string name { get; set; }
|
|
|
+ public string scId{ get; set; }
|
|
|
+ public string tmdId { get; set; }
|
|
|
}
|
|
|
}
|
|
|
}
|