|
@@ -111,7 +111,7 @@ namespace TEAMModeBI.Controllers.BISchool
|
|
if (!jsonElement.TryGetProperty("mode", out JsonElement mode)) return Ok(new { state = 1, message = "mode参数错误!" }); //del删除权限 up更新权限
|
|
if (!jsonElement.TryGetProperty("mode", out JsonElement mode)) return Ok(new { state = 1, message = "mode参数错误!" }); //del删除权限 up更新权限
|
|
if (!jsonElement.TryGetProperty("paramPower", out JsonElement paramPower)) return Ok(new { state = 1, message = "paramPower参数错误!" });
|
|
if (!jsonElement.TryGetProperty("paramPower", out JsonElement paramPower)) return Ok(new { state = 1, message = "paramPower参数错误!" });
|
|
|
|
|
|
- List<reoleds> havepower = new List<reoleds>(); //已存在的权限
|
|
|
|
|
|
+ List<Exist> havepower = new List<Exist>(); //已存在的
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
|
|
|
//更新權限
|
|
//更新權限
|
|
@@ -142,7 +142,7 @@ namespace TEAMModeBI.Controllers.BISchool
|
|
var bools = st.permissions.Find(x => x.Equals($"{pm}"));
|
|
var bools = st.permissions.Find(x => x.Equals($"{pm}"));
|
|
if (!string.IsNullOrEmpty($"{bools}"))
|
|
if (!string.IsNullOrEmpty($"{bools}"))
|
|
{
|
|
{
|
|
- havepower.Add(new reoleds { ID = id.GetString(), relos = bools });
|
|
|
|
|
|
+ havepower.Add(new Exist { ID = id.GetString(), name = bools });
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -164,89 +164,128 @@ namespace TEAMModeBI.Controllers.BISchool
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// 批量创校 --完成带测验
|
|
|
|
|
|
+ /// 批量创校
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="school"></param>
|
|
/// <param name="school"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
[ProducesDefaultResponseType]
|
|
[ProducesDefaultResponseType]
|
|
[HttpPost("batch-createschool")]
|
|
[HttpPost("batch-createschool")]
|
|
- public async Task<IActionResult> batchCreateSchool(School school, string number)
|
|
|
|
|
|
+ public async Task<IActionResult> batchCreateSchool(List<BISchool> bISchools)
|
|
{
|
|
{
|
|
try
|
|
try
|
|
{
|
|
{
|
|
- List<School> school_list = new List<School>();
|
|
|
|
- //创建多个学校
|
|
|
|
- for (int i = 0; i < int.Parse(number); i++)
|
|
|
|
- {
|
|
|
|
- string id = $"{school.id}_{i}";
|
|
|
|
- var client = _azureCosmos.GetCosmosClient();
|
|
|
|
- var schoolContainer = client.GetContainer(Constant.TEAMModelOS, "School");
|
|
|
|
- var response = await schoolContainer.ReadItemStreamAsync(id, new PartitionKey($"Base"));
|
|
|
|
- if (response.Status == 200)
|
|
|
|
|
|
+ List<BISchool> schools = new List<BISchool>();
|
|
|
|
+
|
|
|
|
+ if (bISchools.Count > 0)
|
|
|
|
+ {
|
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
|
+ foreach (BISchool bischool in bISchools)
|
|
{
|
|
{
|
|
- string sql = $"select distinct value(c) from c jion A1 in c.schools where A1.schoolID='{id}'";
|
|
|
|
- List<Teacher> teacher_list = new List<Teacher>();
|
|
|
|
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
|
|
|
|
|
|
+ var schoolStatus = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{bischool.id}", new PartitionKey($"Base"));
|
|
|
|
+ if (schoolStatus.Status == 200)
|
|
{
|
|
{
|
|
- teacher_list.Add(item);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- foreach (var item in teacher_list)
|
|
|
|
|
|
+ schools.Add(bischool);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
{
|
|
{
|
|
- TeacherSchool teacherSchool = item.schools.Find(x => x.schoolId.Equals(id));
|
|
|
|
- if (teacherSchool != null)
|
|
|
|
|
|
+ List<Period> periods = new List<Period>();
|
|
|
|
+ string campusId = Guid.NewGuid().ToString();
|
|
|
|
+ bischool.period.ForEach(x =>
|
|
{
|
|
{
|
|
- teacherSchool.name = $"{school.name}_{i}";
|
|
|
|
- teacherSchool.picture = school.picture;
|
|
|
|
- teacherSchool.areaId = school.areaId;
|
|
|
|
|
|
+ periods.Add(new Period { id = Guid.NewGuid().ToString(), name = x, campusId = campusId });
|
|
|
|
+ });
|
|
|
|
+ School upSchool = new School
|
|
|
|
+ {
|
|
|
|
+ id = bischool.id,
|
|
|
|
+ name = bischool.name,
|
|
|
|
+ size = 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,
|
|
|
|
+ timeZone = new TEAMModelOS.SDK.Models.TimeZone { label = "(UTC+08:00) 北京,重庆,香港特别行政区,乌鲁木齐", value = "+08:00" },
|
|
|
|
+ type = 2,
|
|
|
|
+ pk = "School",
|
|
|
|
+ ttl = -1,
|
|
|
|
+ schoolCode = bischool.id,
|
|
|
|
+ period = periods
|
|
|
|
+ };
|
|
|
|
+ //创建学校
|
|
|
|
+ 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>($"{bischool.admin}", new PartitionKey("Base"));
|
|
}
|
|
}
|
|
- await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(item, item.id, new PartitionKey($"Base"));
|
|
|
|
- }
|
|
|
|
- school.id = id;
|
|
|
|
- school = await schoolContainer.UpsertItemAsync(school, new PartitionKey($"Base"));
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- school.code = "Base";
|
|
|
|
- school.id = $"{school.id}_{i}";
|
|
|
|
- school = await schoolContainer.CreateItemAsync(school, new PartitionKey($"Base"));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ catch
|
|
|
|
+ {
|
|
|
|
+ }
|
|
|
|
+ if (teacher != null)
|
|
|
|
+ {
|
|
|
|
+ //教师存在,在该教师信息中添加要管理的学校信息
|
|
|
|
+ teacher.schools.Add(new Teacher.TeacherSchool { schoolId = bischool.id, name = bischool.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() });
|
|
|
|
+ await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, bischool.admin, new PartitionKey("Base"));
|
|
|
|
+ SchoolTeacher schoolTeacher = new SchoolTeacher
|
|
|
|
+ {
|
|
|
|
+ id = bischool.admin,
|
|
|
|
+ code = $"Teacher-{bischool.id}",
|
|
|
|
+ roles = new List<string> { "admin", "teacher" },
|
|
|
|
+ job = "管理员",
|
|
|
|
+ name = teacher.name,
|
|
|
|
+ picture = teacher.picture,
|
|
|
|
+ status = "join",
|
|
|
|
+ createTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
|
|
|
|
+ pk = "Teacher",
|
|
|
|
+ ttl = -1
|
|
|
|
+ };
|
|
|
|
|
|
- ////创一个学校案例
|
|
|
|
- //var client = _azureCosmos.GetCosmosClient();
|
|
|
|
- //var schoolContainer = client.GetContainer(Constant.TEAMModelOS, "School");
|
|
|
|
- //var response = await schoolContainer.ReadItemStreamAsync(school.id, new PartitionKey($"Base"));
|
|
|
|
- //if (response.Status == 200)
|
|
|
|
- //{
|
|
|
|
- // string sql = $"select distinct value(c) from c jion A1 in c.schools where A1.schoolID='{school.id}'";
|
|
|
|
- // List<Teacher> teacher_list = new List<Teacher>();
|
|
|
|
- // await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
|
|
|
|
- // {
|
|
|
|
- // teacher_list.Add(item);
|
|
|
|
- // }
|
|
|
|
|
|
+ await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").UpsertItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey(schoolTeacher.code));
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ //不存在 新建教师和新建要管理的学校信息
|
|
|
|
+ Teacher addteacher = new Teacher
|
|
|
|
+ {
|
|
|
|
+ id = bischool.admin,
|
|
|
|
+ pk = "Base",
|
|
|
|
+ code = "Base",
|
|
|
|
+ name = $"{bischool.name}-管理员"?.ToString(),
|
|
|
|
+ picture = "",
|
|
|
|
+ //创建账号并第一次登录IES5则默认赠送1G
|
|
|
|
+ size = 1,
|
|
|
|
+ defaultSchool = bischool.id,
|
|
|
|
+ schools = new List<Teacher.TeacherSchool>() { new TeacherSchool { schoolId = bischool.id, name = bischool.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() } }
|
|
|
|
+ };
|
|
|
|
|
|
- // foreach (var item in teacher_list)
|
|
|
|
- // {
|
|
|
|
- // TeacherSchool teacherSchool = item.schools.Find(x => x.schoolId.Equals(school.id));
|
|
|
|
- // if (teacherSchool != null)
|
|
|
|
- // {
|
|
|
|
- // teacherSchool.name = school.name;
|
|
|
|
- // teacherSchool.picture = school.picture;
|
|
|
|
- // teacherSchool.areaId = school.areaId;
|
|
|
|
- // }
|
|
|
|
- // await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(item, item.id, new PartitionKey($"Base"));
|
|
|
|
- // }
|
|
|
|
- // school = await schoolContainer.UpsertItemAsync(school, new PartitionKey($"Base"));
|
|
|
|
- //}
|
|
|
|
- //else
|
|
|
|
- //{
|
|
|
|
- // school.code = "Base";
|
|
|
|
- // school = await schoolContainer.CreateItemAsync(school,new PartitionKey($"Base"));
|
|
|
|
- //}
|
|
|
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(addteacher, new PartitionKey("Base"));
|
|
|
|
+ SchoolTeacher schoolTeacher = new SchoolTeacher
|
|
|
|
+ {
|
|
|
|
+ id = bischool.admin,
|
|
|
|
+ code = $"Teacher-{bischool.id}",
|
|
|
|
+ roles = new List<string> { "admin", "teacher" },
|
|
|
|
+ job = "管理员",
|
|
|
|
+ name = bischool.admin,
|
|
|
|
+ picture = "",
|
|
|
|
+ status = "join",
|
|
|
|
+ createTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
|
|
|
|
+ pk = "Teacher",
|
|
|
|
+ ttl = -1
|
|
|
|
+ };
|
|
|
|
|
|
- return Ok(new { school_list });
|
|
|
|
|
|
+ await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").UpsertItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey(schoolTeacher.code));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else return Ok(new { state = 1, message = "创校信息为空" });
|
|
|
|
|
|
|
|
+ if (schools.Count > 0)
|
|
|
|
+ return Ok(new { state = 201, message = "已有部分学校批量创建成功;学校编号已经重复!请检查学校编号!", schools = schools });
|
|
|
|
+ else
|
|
|
|
+ return Ok(new { state = 200, message = "批量创校已全部完成" });
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|
|
{
|
|
{
|
|
@@ -255,15 +294,54 @@ namespace TEAMModeBI.Controllers.BISchool
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 批量创校的数据结构
|
|
|
|
+ /// </summary>
|
|
|
|
+ public record BISchool()
|
|
|
|
+ {
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 学校ID
|
|
|
|
+ /// </summary>
|
|
|
|
+ public string id { get; set; }
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 学校名称
|
|
|
|
+ /// </summary>
|
|
|
|
+ public string name { get; set; }
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 学校管理员
|
|
|
|
+ /// </summary>
|
|
|
|
+ public string admin { get; set; }
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 学校的学段
|
|
|
|
+ /// </summary>
|
|
|
|
+ public List<string> period { get; set; }
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 学校空间大小
|
|
|
|
+ /// </summary>
|
|
|
|
+ public int size { get; set; }
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 地区
|
|
|
|
+ /// </summary>
|
|
|
|
+ public string region { get; set; }
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 省份
|
|
|
|
+ /// </summary>
|
|
|
|
+ public string province { get; set; }
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 城市
|
|
|
|
+ /// </summary>
|
|
|
|
+ public string city { get; set; }
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 县,区,郡
|
|
|
|
+ /// </summary>
|
|
|
|
+ public string dist { get; set; }
|
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- public record reoleds()
|
|
|
|
|
|
+ public record Exist()
|
|
{
|
|
{
|
|
public string ID { get; set; }
|
|
public string ID { get; set; }
|
|
- public string relos { get; set; }
|
|
|
|
|
|
+ public string name { get; set; }
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|