|
@@ -1391,10 +1391,12 @@ namespace TEAMModelOS.Controllers
|
|
|
[HttpPost("add-area-school-admin")]
|
|
|
public async Task<IActionResult> AddAreaSchoolAdmin(JsonElement data)
|
|
|
{
|
|
|
+ List<School> errorSchool = new List<School>();
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
List<string> tmdids = data.GetProperty("tmdids").ToObject<List<string>>();
|
|
|
data.TryGetProperty("areaId", out JsonElement areaId);
|
|
|
data.TryGetProperty("schoolIds", out JsonElement schoolIds);
|
|
|
+ data.TryGetProperty("addSchool", out JsonElement addSchool);
|
|
|
data.TryGetProperty("areaAdmin", out JsonElement areaAdmin);
|
|
|
List<string> ids = new List<string>();
|
|
|
string idsSql = "";
|
|
@@ -1403,12 +1405,87 @@ namespace TEAMModelOS.Controllers
|
|
|
ids = schoolIds.ToObject<List<string>>();
|
|
|
if (ids.IsNotEmpty())
|
|
|
{
|
|
|
- idsSql = $" or c.id in ({string.Join(",", ids.Select(x => $"'{x}'"))})";
|
|
|
+ idsSql = $" c.id in ({string.Join(",", ids.Select(x => $"'{x}'"))})";
|
|
|
}
|
|
|
}
|
|
|
- string areaIdsql = string.IsNullOrWhiteSpace($"{areaId}") ? "-0000000" : $"{areaId}";
|
|
|
- string sql = $"select distinct value(c) from c where c.areaId='{areaIdsql}' {idsSql}";
|
|
|
List<School> schools = new List<School>();
|
|
|
+ if (addSchool.ValueKind.Equals(JsonValueKind.Array))
|
|
|
+ {
|
|
|
+ List<School> codes = new();
|
|
|
+ codes = addSchool.ToObject<List<School>>();
|
|
|
+ List<School> schoolsNew = new List<School>();
|
|
|
+ string _areaId = null;
|
|
|
+ if (!string.IsNullOrWhiteSpace($"{areaId}"))
|
|
|
+ {
|
|
|
+ _areaId = $"{areaId}";
|
|
|
+ }
|
|
|
+ int scale = 0;
|
|
|
+ data.TryGetProperty("scale", out JsonElement _scale);
|
|
|
+ if (!string.IsNullOrWhiteSpace($"{_scale}"))
|
|
|
+ {
|
|
|
+ int.TryParse($"{_scale}", out scale);
|
|
|
+ }
|
|
|
+ int size = 0;
|
|
|
+ data.TryGetProperty("size", out JsonElement _size);
|
|
|
+ if (!string.IsNullOrWhiteSpace($"{_size}"))
|
|
|
+ {
|
|
|
+ int.TryParse($"{_size}", out size);
|
|
|
+ }
|
|
|
+
|
|
|
+ codes.ForEach(x => {
|
|
|
+ string campusId = Guid.NewGuid().ToString();
|
|
|
+ List<Period> periods = new List<Period>();
|
|
|
+ periods.Add(new Period
|
|
|
+ {
|
|
|
+ id = Guid.NewGuid().ToString(),
|
|
|
+ name = x.name,
|
|
|
+ campusId = campusId,
|
|
|
+ semesterCount = 2,
|
|
|
+ gradeCount = 1,
|
|
|
+ grades = new List<string> { "一年级" },
|
|
|
+ subjectCount = 1,
|
|
|
+ subjects = new List<Subject> { new Subject { name = "预设学科", id = Guid.NewGuid().ToString() } },
|
|
|
+ semesters = new List<Semester>
|
|
|
+ {
|
|
|
+ new Semester { name = "上学期", start = 1, month = 9, day = 1, id = Guid.NewGuid().ToString() },
|
|
|
+ new Semester { name = "下学期", start = 0, month = 3, day = 1, id = Guid.NewGuid().ToString() }
|
|
|
+ },
|
|
|
+ });
|
|
|
+ School school = new School
|
|
|
+ {
|
|
|
+ id = x.id,
|
|
|
+ name = x.name,
|
|
|
+ size = size,
|
|
|
+ code = "Base",
|
|
|
+ campuses = new List<Campus> { new Campus { name = x.name, id = campusId } },
|
|
|
+ region = "中国",
|
|
|
+ province = x.province,
|
|
|
+ city = $"{x.city}",
|
|
|
+ timeZone = new SDK.Models.TimeZone { label = "(UTC+08:00) 北京,重庆,香港特别行政区,乌鲁木齐", value = "+08:00" },
|
|
|
+ type = 1,
|
|
|
+ pk = "School",
|
|
|
+ ttl = -1,
|
|
|
+ schoolCode = x.id,
|
|
|
+ dist = $"{x.dist}",
|
|
|
+ period = periods,
|
|
|
+ areaId = String.IsNullOrWhiteSpace($"{areaId}") ? null: $"{areaId}",
|
|
|
+ standard = $"standard2"
|
|
|
+ };
|
|
|
+ schoolsNew.Add(school);
|
|
|
+ });
|
|
|
+ foreach (var sch in schoolsNew) {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS,Constant.School).CreateItemAsync(sch,new PartitionKey("Base"));
|
|
|
+ schools.Add(sch);
|
|
|
+ }
|
|
|
+ catch (CosmosException ex ){
|
|
|
+ errorSchool.Add(sch);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ string areaIdsql = string.IsNullOrWhiteSpace($"{areaId}") ? "-0000000" : $"{areaId}";
|
|
|
+ string sql = $"select distinct value(c) from c where {idsSql}";
|
|
|
await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.School).GetItemQueryIterator<School>(
|
|
|
queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
|
|
|
{
|
|
@@ -1442,6 +1519,29 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
foreach (var school in schools)
|
|
|
{
|
|
|
+ if (!string.IsNullOrWhiteSpace($"{areaId}")) {
|
|
|
+ school.areaId= $"{areaId}";
|
|
|
+ }
|
|
|
+ data.TryGetProperty("scale", out JsonElement _scale);
|
|
|
+ if (!string.IsNullOrWhiteSpace($"{_scale}"))
|
|
|
+ {
|
|
|
+ int scale = 0;
|
|
|
+ int.TryParse($"{_scale}",out scale);
|
|
|
+ if (scale > 0) {
|
|
|
+ school.scale = scale;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ data.TryGetProperty("size", out JsonElement _size);
|
|
|
+ if (!string.IsNullOrWhiteSpace($"{_size}"))
|
|
|
+ {
|
|
|
+ int size = 0;
|
|
|
+ int.TryParse($"{_size}", out size);
|
|
|
+ if (size > 0)
|
|
|
+ {
|
|
|
+ school.size = size;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync(school, school.id, new PartitionKey("Base"));
|
|
|
Azure.Response response = await client.GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemStreamAsync(tmdid, new PartitionKey($"Teacher-{school.id}"));
|
|
|
if (response.Status == 200)
|
|
|
{
|
|
@@ -1510,7 +1610,7 @@ namespace TEAMModelOS.Controllers
|
|
|
await client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync(teacher, tmdid, new PartitionKey($"Base"));
|
|
|
teachers.Add(teacher);
|
|
|
}
|
|
|
- return Ok(new { teachers, schoolsTeachers });
|
|
|
+ return Ok(new { teachers, schoolsTeachers, errorSchool });
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -1957,14 +2057,32 @@ namespace TEAMModelOS.Controllers
|
|
|
await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync<School>(item, item.id, new PartitionKey(item.code));
|
|
|
}
|
|
|
return Ok(schoolsSet);
|
|
|
+ } /// <summary>
|
|
|
+ /// 修复学校课例及blob计算
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("fix-teacher-private-lesson-record")]
|
|
|
+ public async Task<IActionResult> FixTeacherPrivateLessonRecord(JsonElement json)
|
|
|
+ {
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ string sql = " SELECT distinct value(c) FROM c where c.pk='LessonRecord' ";
|
|
|
+ List<LessonRecord> lessonRecords = new List<LessonRecord>();
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryIterator<LessonRecord>(queryText: sql, requestOptions: new QueryRequestOptions {}))
|
|
|
+ {
|
|
|
+ item.code = "LessonRecord";
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(item,new PartitionKey (item.code));
|
|
|
+ lessonRecords.Add(item);
|
|
|
+ }
|
|
|
+ return Ok(lessonRecords);
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 修复学校课例及blob计算
|
|
|
- /// </summary>
|
|
|
- /// <param name="jsonElement"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [HttpPost("fix-school-lesson-record")]
|
|
|
+ /// <summary>
|
|
|
+ /// 修复学校课例及blob计算
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("fix-school-lesson-record")]
|
|
|
public async Task<IActionResult> FixSchoolLessonRecord(JsonElement json)
|
|
|
{
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
@@ -2103,7 +2221,7 @@ namespace TEAMModelOS.Controllers
|
|
|
else if ($"{scope}".Equals("private"))
|
|
|
{
|
|
|
blobname = $"{tmdid}";
|
|
|
- code = $"LessonRecord-{tmdid}";
|
|
|
+ code = $"LessonRecord";
|
|
|
tbname = "Teacher";
|
|
|
}
|
|
|
//如果有更新 则去读取/{_lessonId}/IES/base.json
|