|
@@ -143,8 +143,9 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
|
try
|
|
|
{
|
|
|
var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
|
|
|
- List<BISchool> schools = new List<BISchool>();
|
|
|
- List<BISchool> userScs = new List<BISchool>();
|
|
|
+ List<BISchool> schools = new();
|
|
|
+ List<BISchool> userScs = new();
|
|
|
+ List<BISchool> cutArea = new();
|
|
|
StringBuilder stringBuilder = new StringBuilder($"{_tmdName}【{_tmdId}】使用批量创校功能:");
|
|
|
var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
var tableClient = _azureStorage.GetCloudTableClient();
|
|
@@ -161,143 +162,159 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
|
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)
|
|
|
{
|
|
|
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)
|
|
|
+ if (isSYNCArea == false)
|
|
|
{
|
|
|
- string campusId = Guid.NewGuid().ToString();
|
|
|
- School upSchool = new School
|
|
|
+ CreateSchoolInfo createSchoolInfo = new CreateSchoolInfo()
|
|
|
{
|
|
|
- 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,
|
|
|
+ id = "",
|
|
|
+ name = bischool.name,
|
|
|
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 = string.IsNullOrEmpty(bischool.areaId) ? "" : bischool.areaId,
|
|
|
- standard = string.IsNullOrEmpty(bischool.standard) ? "" : bischool.standard,
|
|
|
- schoolCode = createSchoolInfo.id,
|
|
|
- period = PresetSchoolPeriod(bischool.period, foundSchools.lang, campusId),
|
|
|
- scale = bischool.size >= 300 ? 500 : 0,
|
|
|
- createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
|
|
|
+ aname = "",
|
|
|
+ createCount = 0,
|
|
|
};
|
|
|
|
|
|
- stringBuilder.Append($"创建学校:{upSchool.name}【{upSchool.id}】");
|
|
|
- //创建学校
|
|
|
- await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<School>(upSchool, new PartitionKey(upSchool.code));
|
|
|
- Teacher teacher = null;
|
|
|
- try
|
|
|
- {
|
|
|
- //查询该教师是否存在
|
|
|
- teacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>($"{coreUser.id}", new PartitionKey("Base"));
|
|
|
- }
|
|
|
- catch
|
|
|
- {
|
|
|
- }
|
|
|
- if (teacher != null)
|
|
|
+ //生成学校ID
|
|
|
+ bool tempStaus = true;
|
|
|
+ do
|
|
|
{
|
|
|
- //教师存在,在该教师信息中添加要管理的学校信息
|
|
|
- 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 SchoolTeacher
|
|
|
- {
|
|
|
- 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
|
|
|
+ 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)
|
|
|
{
|
|
|
- //不存在 新建教师和新建要管理的学校信息
|
|
|
- Teacher addteacher = new Teacher
|
|
|
+ string campusId = Guid.NewGuid().ToString();
|
|
|
+ School upSchool = new()
|
|
|
{
|
|
|
- id = coreUser.id,
|
|
|
- pk = "Base",
|
|
|
+ id = createSchoolInfo.id,
|
|
|
+ name = bischool.name,
|
|
|
+ size = bischool.size == 0 ? 100 : bischool.size,
|
|
|
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() } }
|
|
|
+ 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}】");
|
|
|
- try
|
|
|
+ stringBuilder.Append($"创建学校:{upSchool.name}【{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)
|
|
|
{
|
|
|
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(addteacher, new PartitionKey("Base"));
|
|
|
+ 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 SchoolTeacher
|
|
|
+ {
|
|
|
+ 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));
|
|
|
}
|
|
|
- catch { }
|
|
|
-
|
|
|
- SchoolTeacher schoolTeacher = new SchoolTeacher
|
|
|
+ else
|
|
|
{
|
|
|
- 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
|
|
|
- };
|
|
|
+ //不存在 新建教师和新建要管理的学校信息
|
|
|
+ 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"));
|
|
|
|
|
|
- stringBuilder.Append($"教师权限:{string.Join(",", schoolTeacher.roles)}");
|
|
|
- try
|
|
|
- {
|
|
|
+ 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));
|
|
|
}
|
|
|
- catch { }
|
|
|
}
|
|
|
}
|
|
|
+ else cutArea.Add(bischool);
|
|
|
}
|
|
|
else userScs.Add(bischool);
|
|
|
}
|
|
@@ -309,7 +326,7 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
|
//保存操作记录
|
|
|
//await _azureStorage.SaveBILog("school-batchAdd", stringBuilder?.ToString(), _dingDing, httpContext: HttpContext);
|
|
|
await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "school-batchAdd", stringBuilder?.ToString(), _dingDing, httpContext: HttpContext);
|
|
|
- if (schools.Count > 0 || userScs.Count > 0)
|
|
|
+ if (schools.Count > 0 || userScs.Count > 0 || cutArea.Count >0)
|
|
|
return Ok(new { state = 201, message = "已有部分学校批量创建成功;学校已经重复/或者学校信息有误!请检查学校信息!", schools, userScs });
|
|
|
else
|
|
|
return Ok(new { state = 200, message = "批量创校已全部完成" });
|
|
@@ -1082,7 +1099,7 @@ namespace TEAMModelBI.Controllers.BISchool
|
|
|
/// <summary>
|
|
|
/// 区域标准
|
|
|
/// </summary>
|
|
|
- public string standard { get; set; }
|
|
|
+ //public string standard { get; set; }
|
|
|
}
|
|
|
|
|
|
public record Exist()
|