|
@@ -0,0 +1,305 @@
|
|
|
+using Microsoft.AspNetCore.Hosting;
|
|
|
+using Microsoft.AspNetCore.Http;
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
+using Microsoft.Extensions.Configuration;
|
|
|
+using Microsoft.Extensions.Options;
|
|
|
+using System.Net.Http;
|
|
|
+using TEAMModelOS.SDK.DI.CoreAPI;
|
|
|
+using TEAMModelOS.SDK.DI;
|
|
|
+using TEAMModelOS.SDK;
|
|
|
+using TEAMModelOS.Models;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using System.Text.Json;
|
|
|
+using System.IO;
|
|
|
+using TEAMModelBI.Models;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Text;
|
|
|
+using TEAMModelOS.SDK.Extension;
|
|
|
+using System;
|
|
|
+using TEAMModelOS.SDK.Models;
|
|
|
+using Azure.Cosmos;
|
|
|
+using System.Linq;
|
|
|
+using TEAMModelOS.SDK.Context.Constant;
|
|
|
+using Pipelines.Sockets.Unofficial.Arenas;
|
|
|
+
|
|
|
+namespace TEAMModelBI.Controllers.RepairApi
|
|
|
+{
|
|
|
+ [Route("sccholrep")]
|
|
|
+ [ApiController]
|
|
|
+ public class SchoolRepController : ControllerBase
|
|
|
+ {
|
|
|
+
|
|
|
+ private readonly AzureCosmosFactory _azureCosmos;
|
|
|
+ private readonly DingDing _dingDing;
|
|
|
+ private readonly Option _option;
|
|
|
+ private readonly AzureStorageFactory _azureStorage;
|
|
|
+ private readonly AzureRedisFactory _azureRedis;
|
|
|
+ private readonly IConfiguration _configuration;
|
|
|
+ private readonly NotificationService _notificationService;
|
|
|
+ private readonly CoreAPIHttpService _coreAPIHttpService;
|
|
|
+ private readonly IWebHostEnvironment _environment; //读取文件
|
|
|
+ private readonly IHttpClientFactory _httpClient;
|
|
|
+
|
|
|
+ public SchoolRepController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, AzureRedisFactory azureRedis, IConfiguration configuration, NotificationService notificationService, CoreAPIHttpService coreAPIHttpService, IHttpClientFactory httpClient, IWebHostEnvironment hostingEnvironment)
|
|
|
+ {
|
|
|
+ _azureCosmos = azureCosmos;
|
|
|
+ _dingDing = dingDing;
|
|
|
+ _azureStorage = azureStorage;
|
|
|
+ _option = option?.Value;
|
|
|
+ _azureRedis = azureRedis;
|
|
|
+ _configuration = configuration;
|
|
|
+ _notificationService = notificationService;
|
|
|
+ _coreAPIHttpService = coreAPIHttpService;
|
|
|
+ _httpClient = httpClient;
|
|
|
+ _environment = hostingEnvironment;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 添加新学段的学校
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("set-allscperiod")]
|
|
|
+ public async Task<IActionResult> SetAllScPeriod(JsonElement jsonElement)
|
|
|
+ {
|
|
|
+ jsonElement.TryGetProperty("Language", out JsonElement Language);
|
|
|
+ jsonElement.TryGetProperty("scId", out JsonElement scId);
|
|
|
+ jsonElement.TryGetProperty("periodName", out JsonElement periodName);
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
+ var builder = $"{_environment.ContentRootPath}/JsonFile/Preset/LangSchoolConfig.json";
|
|
|
+ StreamReader streamReader = new(new FileStream(builder, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8);
|
|
|
+ StringBuilder stringBuilder = new();
|
|
|
+ string text;
|
|
|
+ string scName = "默认学段";
|
|
|
+ while ((text = streamReader.ReadLine()) != null)
|
|
|
+ {
|
|
|
+ stringBuilder.Append(text.ToString());
|
|
|
+ }
|
|
|
+ streamReader.Close();
|
|
|
+ string input = stringBuilder.ToString();
|
|
|
+ List<SchoolConfig> schoolConfigs = input.ToObject<List<SchoolConfig>>();
|
|
|
+ SchoolConfig schoolConfig = null;
|
|
|
+ if (!string.IsNullOrEmpty($"{Language}"))
|
|
|
+ schoolConfig = schoolConfigs.Find(x => x.Lang.Contains($"{Language}"));
|
|
|
+
|
|
|
+ if (schoolConfig == null)
|
|
|
+ {
|
|
|
+ if ($"{Language}".Contains("en"))
|
|
|
+ schoolConfig = schoolConfigs.Find(x => x.Lang.Contains("en-US"));
|
|
|
+ else
|
|
|
+ schoolConfig = schoolConfigs.Find(x => x.Lang.Contains("zh-CN"));
|
|
|
+ }
|
|
|
+ string campusId = Guid.NewGuid().ToString();
|
|
|
+
|
|
|
+ StringBuilder noPeriodScSql = new("SELECT value(c) FROM c ");
|
|
|
+ List<School> allSc = new();
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty($"{scId}"))
|
|
|
+ noPeriodScSql.Append($" where c.id='{scId}'");
|
|
|
+ else
|
|
|
+ noPeriodScSql.Append($" join sp in c.period where c.code = 'Base' AND ARRAY_LENGTH(sp.grades) = 0 OR ARRAY_LENGTH(sp.subjects) = 0");
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty($"{periodName}"))
|
|
|
+ scName = $"{periodName}";
|
|
|
+
|
|
|
+ await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<School>(queryText: "select value(c) from c where c.code='Base' and c.period=[]", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
|
|
|
+ {
|
|
|
+ allSc.Add(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<School>(queryText:noPeriodScSql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
|
|
|
+ {
|
|
|
+ allSc.Add(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach (var school in allSc)
|
|
|
+ {
|
|
|
+ if (school.name.Contains("幼儿园"))
|
|
|
+ {
|
|
|
+ string name = null;
|
|
|
+ List<Subject> subjects = new();
|
|
|
+ switch ($"{Language}")
|
|
|
+ {
|
|
|
+ case "zh-CN":
|
|
|
+ name = "学前";
|
|
|
+ subjects.Add(new Subject { id = Guid.NewGuid().ToString(), name = "语言", type = 1 });
|
|
|
+ break;
|
|
|
+ case "zh-TW":
|
|
|
+ name = "學前";
|
|
|
+ subjects.Add(new Subject { id = Guid.NewGuid().ToString(), name = "語言", type = 1 });
|
|
|
+ break;
|
|
|
+ case "en-US":
|
|
|
+ name = "Pre-school";
|
|
|
+ subjects.Add(new Subject { id = Guid.NewGuid().ToString(), name = "language", type = 1 });
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (school.period.Count > 0)
|
|
|
+ {
|
|
|
+ var grade = school.period.Find(sg => sg.grades.Count == 0);
|
|
|
+ if (grade.grades.Count == 0)
|
|
|
+ grade.grades = new List<string>() { name };
|
|
|
+
|
|
|
+ var tempSub = school.period.Find(sg => sg.semesters.Count == 0);
|
|
|
+ if (tempSub.semesters.Count == 0)
|
|
|
+ tempSub.subjects = subjects;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (school.campuses.Count > 0)
|
|
|
+ campusId = school.campuses.Select(x => x.id).FirstOrDefault().ToString();
|
|
|
+
|
|
|
+ school.period.Add(new Period
|
|
|
+ {
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ if (!school.campuses.Select(x => x.id).Contains(campusId))
|
|
|
+ school.campuses.Add(new Campus { name = school.name, id = campusId });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (school.period.Count > 0)
|
|
|
+ {
|
|
|
+ var grade = school.period.Find(sg => sg.grades.Count == 0);
|
|
|
+ if (grade.grades.Count == 0)
|
|
|
+ grade.grades = schoolConfig.grades;
|
|
|
+
|
|
|
+ var subject = school.period.Find(sg => sg.subjects.Count == 0);
|
|
|
+ if (subject.subjects.Count == 0)
|
|
|
+ {
|
|
|
+ subject.subjects = new List<Subject>() {
|
|
|
+ new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[0].name,type=schoolConfig.PresetSubject[0].type },
|
|
|
+ new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[1].name,type=schoolConfig.PresetSubject[1].type },
|
|
|
+ new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[2].name,type=schoolConfig.PresetSubject[2].type }
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (school.campuses.Count > 0)
|
|
|
+ campusId = school.campuses.Select(x => x.id).FirstOrDefault().ToString();
|
|
|
+
|
|
|
+ school.period.Add(new Period
|
|
|
+ {
|
|
|
+ id = Guid.NewGuid().ToString(),
|
|
|
+ name = scName,
|
|
|
+ campusId = campusId,
|
|
|
+ semesters = new List<Semester>() { new Semester { name = schoolConfig.semester[0].term, start = schoolConfig.semester[0].start, month = schoolConfig.semester[0].month, day = schoolConfig.semester[0].day, id = Guid.NewGuid().ToString() },
|
|
|
+ new Semester { name = schoolConfig.semester[1].term, start = schoolConfig.semester[1].start, month = schoolConfig.semester[1].month, day = schoolConfig.semester[1].day, id = Guid.NewGuid().ToString() } },
|
|
|
+ subjects = new List<Subject>() {
|
|
|
+ new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[0].name,type=schoolConfig.PresetSubject[0].type },
|
|
|
+ new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[1].name,type=schoolConfig.PresetSubject[1].type },
|
|
|
+ new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[2].name,type=schoolConfig.PresetSubject[2].type }
|
|
|
+ },
|
|
|
+ grades = schoolConfig.grades,
|
|
|
+ analysis = new Analysis()
|
|
|
+ {
|
|
|
+ type = new List<ExamSimple>() { new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[0].name },
|
|
|
+ new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[1].name },
|
|
|
+ new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[2].name },
|
|
|
+ new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[3].name } },
|
|
|
+ income = schoolConfig.PresetExam[0].income,
|
|
|
+ eugenics = schoolConfig.PresetExam[0].eugenics,
|
|
|
+ touch = schoolConfig.PresetExam[0].touch
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (!school.campuses.Select(x => x.id).Contains(campusId))
|
|
|
+ school.campuses.Add(new Campus { name = school.name, id = campusId });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ School rSchool = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(school, school.id, new PartitionKey("Base"));
|
|
|
+ }
|
|
|
+
|
|
|
+ return Ok(new { state = RespondCode.Ok });
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 新增学校学段(多个)
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("set-scperiod")]
|
|
|
+ public async Task<IActionResult> SetScPeriod(JsonElement jsonElement)
|
|
|
+ {
|
|
|
+ if (!jsonElement.TryGetProperty("scId", out JsonElement scId)) return BadRequest();
|
|
|
+ if (!jsonElement.TryGetProperty("periodName", out JsonElement periodName)) return BadRequest();
|
|
|
+
|
|
|
+ List<string> periodNames = $"{periodName}".ToObject<List<string>>();
|
|
|
+ jsonElement.TryGetProperty("Language", out JsonElement Language);
|
|
|
+
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
+ var builder = $"{_environment.ContentRootPath}/JsonFile/Preset/LangSchoolConfig.json";
|
|
|
+ StreamReader streamReader = new(new FileStream(builder, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8);
|
|
|
+ StringBuilder stringBuilder = new();
|
|
|
+ string text;
|
|
|
+ while ((text = streamReader.ReadLine()) != null)
|
|
|
+ {
|
|
|
+ stringBuilder.Append(text.ToString());
|
|
|
+ }
|
|
|
+ streamReader.Close();
|
|
|
+ string input = stringBuilder.ToString();
|
|
|
+ List<SchoolConfig> schoolConfigs = input.ToObject<List<SchoolConfig>>();
|
|
|
+ SchoolConfig schoolConfig = null;
|
|
|
+ if (!string.IsNullOrEmpty($"{Language}"))
|
|
|
+ schoolConfig = schoolConfigs.Find(x => x.Lang.Contains($"{Language}"));
|
|
|
+
|
|
|
+ if (schoolConfig == null)
|
|
|
+ {
|
|
|
+ if ($"{Language}".Contains("en"))
|
|
|
+ schoolConfig = schoolConfigs.Find(x => x.Lang.Contains("en-US"));
|
|
|
+ else
|
|
|
+ schoolConfig = schoolConfigs.Find(x => x.Lang.Contains("zh-CN"));
|
|
|
+ }
|
|
|
+ string campusId = Guid.NewGuid().ToString();
|
|
|
+ School school = null;
|
|
|
+
|
|
|
+ school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{scId}", new PartitionKey("Base"));
|
|
|
+
|
|
|
+ if (school != null)
|
|
|
+ {
|
|
|
+ foreach (var item in periodNames)
|
|
|
+ {
|
|
|
+ if (school.campuses.Count > 0)
|
|
|
+ campusId = school.campuses.Select(x => x.id).FirstOrDefault().ToString();
|
|
|
+
|
|
|
+ school.period.Add(new Period
|
|
|
+ {
|
|
|
+ id = Guid.NewGuid().ToString(),
|
|
|
+ name = item,
|
|
|
+ campusId = campusId,
|
|
|
+ semesters = new List<Semester>() { new Semester { name = schoolConfig.semester[0].term, start = schoolConfig.semester[0].start, month = schoolConfig.semester[0].month, day = schoolConfig.semester[0].day, id = Guid.NewGuid().ToString() },
|
|
|
+ new Semester { name = schoolConfig.semester[1].term, start = schoolConfig.semester[1].start, month = schoolConfig.semester[1].month, day = schoolConfig.semester[1].day, id = Guid.NewGuid().ToString() } },
|
|
|
+ subjects = new List<Subject>() {
|
|
|
+ new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[0].name,type=schoolConfig.PresetSubject[0].type },
|
|
|
+ new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[1].name,type=schoolConfig.PresetSubject[1].type },
|
|
|
+ new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[2].name,type=schoolConfig.PresetSubject[2].type }
|
|
|
+ },
|
|
|
+ grades = schoolConfig.grades,
|
|
|
+ analysis = new Analysis()
|
|
|
+ {
|
|
|
+ type = new List<ExamSimple>() { new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[0].name },
|
|
|
+ new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[1].name },
|
|
|
+ new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[2].name },
|
|
|
+ new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[3].name } },
|
|
|
+ income = schoolConfig.PresetExam[0].income,
|
|
|
+ eugenics = schoolConfig.PresetExam[0].eugenics,
|
|
|
+ touch = schoolConfig.PresetExam[0].touch
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!school.campuses.Select(x => x.id).Contains(campusId))
|
|
|
+ school.campuses.Add(new Campus { name = school.name, id = campusId });
|
|
|
+ }
|
|
|
+
|
|
|
+ school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(school, school.id, new PartitionKey("Base"));
|
|
|
+
|
|
|
+ return Ok(new { state = RespondCode.Ok, school });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|