BatchSchoolController.cs 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  1. using Azure.Cosmos;
  2. using HTEXLib.COMM.Helpers;
  3. using Microsoft.AspNetCore.Http;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.Extensions.Options;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Dynamic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Text.Json;
  12. using System.Threading.Tasks;
  13. using TEAMModelOS.Models;
  14. using TEAMModelOS.SDK.DI;
  15. using TEAMModelOS.SDK.Extension;
  16. using TEAMModelOS.SDK.Models;
  17. using TEAMModelOS.SDK.Models.Cosmos.BI;
  18. using Microsoft.AspNetCore.Hosting; //引用读取文件
  19. using TEAMModelOS.SDK.Models.Service;
  20. using System.IO;
  21. using System.Net.Http;
  22. using Microsoft.Extensions.Configuration;
  23. using System.Net.Http.Json;
  24. using System.Net;
  25. using TEAMModelBI.Filter;
  26. using TEAMModelBI.Tool.Extension;
  27. using TEAMModelBI.Tool;
  28. using TEAMModelBI.Models;
  29. using TEAMModelBI.Tool.Context;
  30. using TEAMModelBI.DI.BIAzureStorage;
  31. namespace TEAMModelBI.Controllers.BISchool
  32. {
  33. [Route("batchschool")]
  34. [ApiController]
  35. public class BatchSchoolController : ControllerBase
  36. {
  37. private readonly AzureCosmosFactory _azureCosmos;
  38. private readonly DingDing _dingDing;
  39. private readonly Option _option;
  40. private readonly AzureStorageFactory _azureStorage;
  41. private readonly IWebHostEnvironment _environment; //读取文件
  42. private readonly IHttpClientFactory _http;
  43. //读取配置信息
  44. private readonly IConfiguration _configuration;
  45. public readonly string mobel = "学校";
  46. public BatchSchoolController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IWebHostEnvironment hostingEnvironment, IConfiguration configuration, IHttpClientFactory http)
  47. {
  48. _azureCosmos = azureCosmos;
  49. _dingDing = dingDing;
  50. _azureStorage = azureStorage;
  51. _option = option?.Value;
  52. _environment = hostingEnvironment;
  53. _configuration = configuration;
  54. _http = http;
  55. }
  56. /// <summary>
  57. /// 获取BI权限列表
  58. /// </summary>
  59. /// <returns></returns>
  60. [ProducesDefaultResponseType]
  61. [HttpPost("get-teacher-authoritybilist")]
  62. public async Task<IActionResult> GetAuthorityBIList(JsonElement jsonElement)
  63. {
  64. jsonElement.TryGetProperty("site", out JsonElement site);
  65. Dictionary<string, object> dic = new Dictionary<string, object> { { "PartitionKey", "authority-bi" } };
  66. var table = _azureStorage.GetCloudTableClient().GetTableReference("SchoolSetting");
  67. if ($"{site}".Equals(BIConst.GlobalSite))
  68. table = _azureStorage.GetCloudTableClient(BIConst.GlobalSite).GetTableReference("SchoolSetting");
  69. List<Authority> authorityBIList = await table.FindListByDict<Authority>(dic);
  70. return Ok(new { authorityBIList });
  71. }
  72. /// <summary>
  73. /// 通过教师的id和学校的code查询权限
  74. /// </summary>
  75. /// <param name="jsonElement"></param>
  76. /// <returns></returns>
  77. [ProducesDefaultResponseType]
  78. [HttpPost("get-teacherroles")]
  79. public async Task<IActionResult> GetTeacherRoles(JsonElement jsonElement)
  80. {
  81. try
  82. {
  83. if (!jsonElement.TryGetProperty("id", out JsonElement id)) return Ok(new { state = 1, message = "参数错误!" });
  84. if (!jsonElement.TryGetProperty("schoolcode", out JsonElement schoolcode)) return Ok(new { state = 1, message = "参数错误!" });
  85. jsonElement.TryGetProperty("site", out JsonElement site);
  86. var client = _azureCosmos.GetCosmosClient();
  87. string sqltxt = $"select * from c where c.id='{id}'";
  88. List<string> roles = new List<string>();//角色列表
  89. List<string> permissions = new List<string>();//权限列表
  90. var cosmosClient = _azureCosmos.GetCosmosClient();
  91. if ($"{site}".Equals(BIConst.GlobalSite))
  92. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
  93. var schoolRoles = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{id}", new PartitionKey($"Teacher-{schoolcode}"));
  94. if (schoolRoles.Status == 200)
  95. {
  96. using var json = await JsonDocument.ParseAsync(schoolRoles.ContentStream);
  97. if (json.RootElement.TryGetProperty("roles", out JsonElement _roles) && _roles.ValueKind != JsonValueKind.Null)
  98. {
  99. foreach (var obj in _roles.EnumerateArray())
  100. {
  101. roles.Add(obj.GetString());
  102. }
  103. }
  104. if (json.RootElement.TryGetProperty("permissions", out JsonElement _permissions) && _permissions.ValueKind != JsonValueKind.Null)
  105. {
  106. foreach (var obj in _permissions.EnumerateArray())
  107. {
  108. permissions.Add(obj.GetString());
  109. }
  110. }
  111. }
  112. return Ok(new { state = 200, roles = roles, permissions = permissions });
  113. }
  114. catch (Exception ex)
  115. {
  116. await _dingDing.SendBotMsg($"BI,{_option.Location}, /batchschool/get-teacherroles \n{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  117. return BadRequest();
  118. }
  119. }
  120. /// <summary>
  121. /// 批量创校
  122. /// </summary>
  123. /// <param name="school"></param>
  124. /// <returns></returns>
  125. [ProducesDefaultResponseType]
  126. [AuthToken(Roles = "admin,rdc")]
  127. [HttpPost("batch-school")]
  128. public async Task<IActionResult> BatchCreateSchool(FoundSchools foundSchools)
  129. {
  130. try
  131. {
  132. var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  133. List<BISchool> schools = new List<BISchool>();
  134. StringBuilder stringBuilder = new StringBuilder($"{_tmdName}【{_tmdId}】使用批量创校功能:");
  135. var cosmosClient = _azureCosmos.GetCosmosClient();
  136. var tableClient = _azureStorage.GetCloudTableClient();
  137. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  138. if (foundSchools.site.Equals(BIConst.GlobalSite))
  139. {
  140. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
  141. tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
  142. blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
  143. }
  144. if (foundSchools.biSchools.Count > 0)
  145. {
  146. foreach (BISchool bischool in foundSchools.biSchools)
  147. {
  148. List<string> scName = new();
  149. 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") }))
  150. {
  151. scName.Add(item);
  152. }
  153. if (scName.Count <= 0)
  154. {
  155. string tempTmdId = null;
  156. HttpClient httpClient = _http.CreateClient();
  157. string url = _configuration.GetValue<string>("HaBookAuth:CoreId:userinfo");
  158. List<string> mobile = new List<string>() { bischool.admin };
  159. HttpResponseMessage responseMessage = await httpClient.PostAsJsonAsync(url, mobile);
  160. if (responseMessage.StatusCode == HttpStatusCode.OK)
  161. {
  162. string temp = responseMessage.Content.ReadAsStringAsync().Result;
  163. List<JsonElement> json_id = temp.ToObject<List<JsonElement>>();
  164. foreach (var item in json_id)
  165. {
  166. tempTmdId = item.GetProperty("id").ToString();
  167. }
  168. }
  169. string tmdId = !string.IsNullOrEmpty(tempTmdId) ? tempTmdId : bischool.admin;
  170. CreateSchoolInfo createSchoolInfo = new CreateSchoolInfo()
  171. {
  172. province = bischool.province,
  173. id = "",
  174. name = bischool.name,
  175. city = bischool.city,
  176. aname = "",
  177. createCount = 0,
  178. };
  179. //生成学校ID
  180. bool tempStaus = true;
  181. do
  182. {
  183. createSchoolInfo = await SchoolCode.GenerateSchoolCode(createSchoolInfo, _dingDing, _environment);
  184. var schoolStatu = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{createSchoolInfo.id}", new PartitionKey($"Base"));
  185. if (schoolStatu.Status != 200) tempStaus = false;
  186. else createSchoolInfo.createCount = createSchoolInfo.createCount >= 3 ? createSchoolInfo.createCount = 3 : createSchoolInfo.createCount += 1;
  187. } while (tempStaus);
  188. if (createSchoolInfo.id != null)
  189. {
  190. string campusId = Guid.NewGuid().ToString();
  191. School upSchool = new School
  192. {
  193. id = createSchoolInfo.id,
  194. name = bischool.name,
  195. size = bischool.size == 0 ? 100 : bischool.size,
  196. code = "Base",
  197. campuses = new List<Campus> { new Campus { name = bischool.name, id = campusId } },
  198. region = bischool.region,
  199. province = bischool.province,
  200. city = bischool.city,
  201. dist = bischool.dist,
  202. address = bischool.address,
  203. picture = "https://teammodelstorage.blob.core.chinacloudapi.cn/0-public/school/bbf54fb3-3fc8-43ae-a358-107281c174cc.png",
  204. timeZone = new TEAMModelOS.SDK.Models.TimeZone { label = "(UTC+08:00) 北京,重庆,香港特别行政区,乌鲁木齐", value = "+08:00" },
  205. type = string.IsNullOrEmpty(bischool.type.ToString()) ? 1 : bischool.type,
  206. pk = "School",
  207. ttl = -1,
  208. areaId = string.IsNullOrEmpty(bischool.areaId) ? "" : bischool.areaId,
  209. standard = string.IsNullOrEmpty(bischool.standard) ? "" : bischool.standard,
  210. schoolCode = createSchoolInfo.id,
  211. period = PresetSchoolPeriod(bischool.period, foundSchools.lang, campusId),
  212. scale = bischool.size >= 300 ? 500 : 0,
  213. createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
  214. };
  215. stringBuilder.Append($"创建学校:{upSchool.name}【{upSchool.id}】");
  216. //创建学校
  217. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<School>(upSchool, new PartitionKey(upSchool.code));
  218. Teacher teacher = null;
  219. try
  220. {
  221. //查询该教师是否存在
  222. teacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>($"{tmdId}", new PartitionKey("Base"));
  223. }
  224. catch
  225. {
  226. }
  227. if (teacher != null)
  228. {
  229. //教师存在,在该教师信息中添加要管理的学校信息
  230. 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() });
  231. //await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, tmdId, new PartitionKey("Base"));
  232. SchoolTeacher schoolTeacher = new SchoolTeacher
  233. {
  234. id = tmdId,
  235. code = $"Teacher-{createSchoolInfo.id}",
  236. roles = new List<string> { "admin", "teacher" },
  237. job = "管理员",
  238. name = teacher.name,
  239. picture = teacher.picture,
  240. status = "join",
  241. createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
  242. pk = "Teacher",
  243. ttl = -1
  244. };
  245. stringBuilder.Append($"教师信息:{schoolTeacher.name}【{schoolTeacher.id}】,教师权限:{string.Join(",", schoolTeacher.roles)}");
  246. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
  247. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey(schoolTeacher.code));
  248. }
  249. else
  250. {
  251. //不存在 新建教师和新建要管理的学校信息
  252. Teacher addteacher = new Teacher
  253. {
  254. id = tmdId,
  255. pk = "Base",
  256. code = "Base",
  257. name = $"{bischool.name}-管理员"?.ToString(),
  258. picture = "",
  259. //创建账号并第一次登录IES5则默认赠送1G
  260. size = 1,
  261. defaultSchool = createSchoolInfo.id,
  262. createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
  263. schools = new List<Teacher.TeacherSchool>() { new Teacher.TeacherSchool { schoolId = createSchoolInfo.id, name = bischool.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() } }
  264. };
  265. stringBuilder.Append($"没有该教师信息创建的教师信息:{addteacher.name}【{addteacher.id}】");
  266. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(addteacher, new PartitionKey("Base"));
  267. SchoolTeacher schoolTeacher = new SchoolTeacher
  268. {
  269. id = tmdId,
  270. code = $"Teacher-{createSchoolInfo.id}",
  271. roles = new List<string> { "admin", "teacher" },
  272. job = "管理员",
  273. name = $"{tmdId}-管理员",
  274. picture = "",
  275. status = "join",
  276. createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
  277. pk = "Teacher",
  278. ttl = -1
  279. };
  280. stringBuilder.Append($"教师权限:{string.Join(",", schoolTeacher.roles)}");
  281. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey(schoolTeacher.code));
  282. }
  283. }
  284. }
  285. else
  286. {
  287. schools.Add(bischool);
  288. }
  289. }
  290. }
  291. else return Ok(new { state = 1, message = "创校信息为空" });
  292. //保存操作记录
  293. //await _azureStorage.SaveBILog("school-batchAdd", stringBuilder?.ToString(), _dingDing, httpContext: HttpContext);
  294. await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "school-batchAdd", stringBuilder?.ToString(), _dingDing, httpContext: HttpContext);
  295. if (schools.Count > 0)
  296. return Ok(new { state = 201, message = "已有部分学校批量创建成功;学校已经重复!请检查学校信息!", schools });
  297. else
  298. return Ok(new { state = 200, message = "批量创校已全部完成" });
  299. }
  300. catch (Exception ex)
  301. {
  302. await _dingDing.SendBotMsg($"BI,{_option.Location} /batchschool/batch-school \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  303. return BadRequest();
  304. }
  305. }
  306. /// <summary>
  307. /// 依据学校编号查询学校信息;若是没有传学校编号,则查询所有学校信息
  308. /// </summary>
  309. /// <param name="jsonElement"></param>
  310. /// <returns></returns>
  311. [ProducesDefaultResponseType]
  312. [HttpPost("get-schoolsinfo")]
  313. public async Task<IActionResult> GetSchoolsInfo(JsonElement jsonElement)
  314. {
  315. try
  316. {
  317. jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
  318. jsonElement.TryGetProperty("schoolCode", out JsonElement _schoolCode);
  319. jsonElement.TryGetProperty("site", out JsonElement site);
  320. var cosmosClient = _azureCosmos.GetCosmosClient();
  321. if ($"{site}".Equals(BIConst.GlobalSite))
  322. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
  323. int? pageSize = null; //默认不指定返回大小
  324. string continuationToken = string.Empty; //返给前端分页token
  325. string pageToken = default;//接受前端的分页Tolen
  326. bool iscontinuation = false;//是否需要进行分页查询,默认不分页
  327. List<AssistSchool> schoolAssists = new(); //返回学校列表集合
  328. List<string> schoolIds = new();
  329. StringBuilder stringBuilder = new("select c.id,c.code,c.schoolCode,c.name,c.region,c.province,c.city,c.dist,c.size,c.address,c.picture,c.type,c.scale,c.areaId,c.standard from c");
  330. if (jsonElement.TryGetProperty("pageSize", out JsonElement jsonPageSize))
  331. {
  332. if (!jsonPageSize.ValueKind.Equals(JsonValueKind.Undefined) && !jsonPageSize.ValueKind.Equals(JsonValueKind.Null) && jsonPageSize.TryGetInt32(out int tempPageSize))
  333. {
  334. pageSize = tempPageSize;
  335. }
  336. }
  337. if (pageSize != null && pageSize.Value > 0)
  338. {
  339. iscontinuation = true;
  340. }
  341. if (jsonElement.TryGetProperty("contToken", out JsonElement ContToken))
  342. {
  343. pageToken = ContToken.GetString();
  344. }
  345. if (!string.IsNullOrEmpty($"{tmdId}"))
  346. {
  347. schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
  348. }
  349. if (schoolIds.Count > 0)
  350. {
  351. foreach (var id in schoolIds)
  352. {
  353. string sqlTxt = $"select c.id,c.code,c.schoolCode,c.name,c.region,c.province,c.city,c.dist,c.size,c.address,c.picture,c.type,c.scale,c.areaId,c.standard from c where c.id='{id}'";
  354. await foreach (var itemSchool in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<AssistSchool>(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  355. {
  356. schoolAssists.Add(itemSchool);
  357. }
  358. }
  359. }
  360. else
  361. {
  362. if (!string.IsNullOrEmpty($"{_schoolCode}"))
  363. {
  364. stringBuilder.Append($" where c.id='{_schoolCode}'");
  365. }
  366. await foreach (var itemSchool in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: stringBuilder.ToString(), continuationToken: pageToken, requestOptions: new QueryRequestOptions() { MaxItemCount = pageSize, PartitionKey = new PartitionKey("Base") }))
  367. {
  368. using var json = await JsonDocument.ParseAsync(itemSchool.ContentStream);
  369. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt16() > 0)
  370. {
  371. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  372. {
  373. schoolAssists.Add(obj.ToObject<AssistSchool>());
  374. }
  375. if (iscontinuation)
  376. {
  377. continuationToken = itemSchool.GetContinuationToken();
  378. break;
  379. }
  380. }
  381. }
  382. }
  383. schoolAssists.ForEach(async school =>
  384. {
  385. var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(school.id, new PartitionKey("ProductSum"));
  386. if (response.Status == 200)
  387. {
  388. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  389. if (json.RootElement.TryGetProperty("serial", out JsonElement serial) && !serial.ValueKind.Equals(JsonValueKind.Null))
  390. {
  391. school.serial = serial.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
  392. }
  393. if (json.RootElement.TryGetProperty("service", out JsonElement service) && !service.ValueKind.Equals(JsonValueKind.Null))
  394. {
  395. school.service = service.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
  396. }
  397. if (json.RootElement.TryGetProperty("hard", out JsonElement hard) && !hard.ValueKind.Equals(JsonValueKind.Null))
  398. {
  399. school.hard = hard.ToObject<List<SchoolProductSumDataHard>>().Select(x => x.prodCode).ToList();
  400. }
  401. }
  402. school.assists = await CommonFind.FindSchoolRoles(cosmosClient, school.id, "assist");
  403. school.lessonCount = await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals from c ", "School", $"LessonRecord-{school.id}");
  404. });
  405. return Ok(new { state = 200, continuationToken, schoolAssists, });
  406. }
  407. catch (Exception ex)
  408. {
  409. await _dingDing.SendBotMsg($"BI,{_option.Location} /batchschool/get-schoolsinfo \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  410. return BadRequest();
  411. }
  412. }
  413. /// <summary>
  414. /// 使用yieId 关键字 本地效率未测出
  415. /// </summary>
  416. /// <param name="cosmosClient"></param>
  417. /// <param name="schoolAssists"></param>
  418. /// <returns></returns>
  419. private async IAsyncEnumerable<List<AssistSchool>> GetSchools(CosmosClient cosmosClient,List<AssistSchool> schoolAssists)
  420. {
  421. List<AssistSchool> tempSchoolAssists = new();
  422. foreach (var temp in schoolAssists)
  423. {
  424. var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(temp.id, new PartitionKey("ProductSum"));
  425. if (response.Status == 200)
  426. {
  427. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  428. if (json.RootElement.TryGetProperty("serial", out JsonElement serial) && !serial.ValueKind.Equals(JsonValueKind.Null))
  429. {
  430. temp.serial = serial.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
  431. }
  432. if (json.RootElement.TryGetProperty("service", out JsonElement service) && !service.ValueKind.Equals(JsonValueKind.Null))
  433. {
  434. temp.service = service.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
  435. }
  436. if (json.RootElement.TryGetProperty("hard", out JsonElement hard) && !hard.ValueKind.Equals(JsonValueKind.Null))
  437. {
  438. temp.hard = hard.ToObject<List<SchoolProductSumDataHard>>().Select(x => x.prodCode).ToList();
  439. }
  440. }
  441. temp.assists = await CommonFind.FindSchoolRoles(cosmosClient, temp.id, "assist");
  442. tempSchoolAssists.Add(temp);
  443. }
  444. yield return tempSchoolAssists;
  445. }
  446. /// <summary>
  447. /// 取得学校所有顾问列表
  448. /// </summary>
  449. /// <returns></returns>
  450. [ProducesDefaultResponseType]
  451. [HttpPost("get-schoolassist")]
  452. public async Task<IActionResult> GetSchoolAssist(JsonElement jsonElement)
  453. {
  454. try
  455. {
  456. jsonElement.TryGetProperty("site", out JsonElement site);
  457. string schoolId = (jsonElement.TryGetProperty("schoolId", out JsonElement _schoolId)) ? _schoolId.GetString() : string.Empty;
  458. Dictionary<string, List<Dictionary<string, string>>> haveSchoolManger = new Dictionary<string, List<Dictionary<string, string>>>();
  459. string managerWhereOption = (!string.IsNullOrWhiteSpace(schoolId)) ? $" AND c.code = 'Teacher-{schoolId}'" : string.Empty;
  460. //查询学校的顾问
  461. string managerSql = $"SELECT DISTINCT REPLACE(c.code, 'Teacher-', '') AS schoolId, c.id, c.name FROM c WHERE ARRAY_CONTAINS(c.roles, 'assist', true) AND c.pk = 'Teacher' AND c.status = 'join'{managerWhereOption}";
  462. var cosmosClient = _azureCosmos.GetCosmosClient();
  463. if ($"{site}".Equals(BIConst.GlobalSite))
  464. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
  465. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: managerSql, requestOptions: new QueryRequestOptions() { }))
  466. {
  467. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  468. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  469. {
  470. string id = obj.GetProperty("id").GetString(); //管理员ID
  471. string name = obj.GetProperty("name").GetString(); //管理员姓名
  472. string tempSchoolId = obj.GetProperty("schoolId").GetString(); //学校ID
  473. Dictionary<string, string> managerDic = new Dictionary<string, string>();
  474. managerDic.Add("id", id);
  475. managerDic.Add("name", name);
  476. if (haveSchoolManger.ContainsKey(tempSchoolId))
  477. {
  478. haveSchoolManger[tempSchoolId].Add(managerDic);
  479. }
  480. else
  481. {
  482. List<Dictionary<string, string>> managerList = new List<Dictionary<string, string>>();
  483. managerList.Add(managerDic);
  484. haveSchoolManger.Add(tempSchoolId, managerList);
  485. }
  486. }
  487. }
  488. //管理模组学校
  489. List<string> baseModuleSchoos = new List<string>();
  490. string baseWhereOption = (!string.IsNullOrEmpty(schoolId)) ? $" and c.id='{schoolId}'" : string.Empty;
  491. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"select c.id from c join serviceProduct in c.service.product where serviceProduct.prodCode = 'IPDYZYLC' {baseWhereOption}", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Product") }))
  492. {
  493. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  494. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  495. {
  496. string tempSchoolId = obj.GetProperty("id").GetString(); //学校ID
  497. baseModuleSchoos.Add(tempSchoolId);
  498. }
  499. }
  500. //学校信息
  501. List<object> schools = new List<object>();
  502. string schoolWhereOption = (!string.IsNullOrEmpty(schoolId)) ? $" where c.id='{schoolId}'" : string.Empty;
  503. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"select c.id,c.name,c.period,c.schoolCode,c.region,c.province,c.city,c.picture from c {schoolWhereOption}", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  504. {
  505. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  506. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  507. {
  508. dynamic schoolExpando = new ExpandoObject();
  509. schoolExpando.id = obj.GetProperty("id").GetString();
  510. schoolExpando.name = obj.GetProperty("name").GetString();
  511. //schoolExpando.period = obj.GetProperty("period");
  512. schoolExpando.schoolCode = obj.GetProperty("schoolCode").GetString();
  513. schoolExpando.region = obj.GetProperty("region").GetString();
  514. schoolExpando.province = obj.GetProperty("province").GetString();
  515. schoolExpando.city = obj.GetProperty("city").GetString();
  516. schoolExpando.picture = obj.GetProperty("picture").GetString();
  517. if (haveSchoolManger.ContainsKey(schoolExpando.id))
  518. {
  519. schoolExpando.hasMarger = true;
  520. schoolExpando.managers = haveSchoolManger[schoolExpando.id];
  521. }
  522. else
  523. {
  524. schoolExpando.hasMarger = false;
  525. schoolExpando.managers = new List<object>();
  526. }
  527. schoolExpando.hasBaseModule = (baseModuleSchoos.Contains(schoolExpando.id)) ? true : false;
  528. schools.Add(schoolExpando);
  529. }
  530. }
  531. return Ok(new { state = 200, schools });
  532. }
  533. catch (Exception ex)
  534. {
  535. await _dingDing.SendBotMsg($"BI,{_option.Location} /batchschool/get-schools \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  536. return BadRequest();
  537. }
  538. }
  539. /// <summary>
  540. /// 修改学校信息和顾问信息
  541. /// </summary>
  542. /// <param name="jsonElement"></param>
  543. /// <returns></returns>
  544. [ProducesDefaultResponseType]
  545. [AuthToken(Roles = "admin,rdc")]
  546. [HttpPost("upd-schoolassist")]
  547. public async Task<IActionResult> UpdSchoolAssist(JsonElement jsonElement)
  548. {
  549. try
  550. {
  551. if (!jsonElement.TryGetProperty("schoolId", out JsonElement _schoolId)) return BadRequest();
  552. if (!jsonElement.TryGetProperty("name", out JsonElement schoolName)) return BadRequest();
  553. if (!jsonElement.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
  554. if (!jsonElement.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
  555. //if (!jsonElement.TryGetProperty("period", out JsonElement period)) return BadRequest();
  556. if (!jsonElement.TryGetProperty("picture", out JsonElement picture)) return BadRequest();
  557. if (!jsonElement.TryGetProperty("size", out JsonElement size)) return BadRequest();
  558. if (!jsonElement.TryGetProperty("scale", out JsonElement scale)) return BadRequest();
  559. if (!jsonElement.TryGetProperty("assistId", out JsonElement _assistId)) return BadRequest();
  560. if (!jsonElement.TryGetProperty("type", out JsonElement _type)) return BadRequest();
  561. jsonElement.TryGetProperty("site", out JsonElement site);
  562. var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  563. List<string> assistId = _assistId.ToObject<List<string>>();
  564. //List<string> periodS = period.ToObject<List<string>>();
  565. Dictionary<string, List<Dictionary<string, string>>> haveSchoolManger = new Dictionary<string, List<Dictionary<string, string>>>();
  566. var cosmosClient = _azureCosmos.GetCosmosClient();
  567. var tableClient = _azureStorage.GetCloudTableClient();
  568. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  569. if ($"{site}".Equals(BIConst.GlobalSite))
  570. {
  571. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
  572. tableClient = _azureStorage.GetCloudTableClient(BIConst.GlobalSite);
  573. blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.GlobalSite);
  574. }
  575. School tempShool = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{_schoolId}", new PartitionKey("Base"));
  576. if (tempShool != null)
  577. {
  578. List<Period> periods = new List<Period>();
  579. string campusId = Guid.NewGuid().ToString();
  580. //periodS.ForEach(x =>
  581. //{
  582. // periods.Add(new Period { id = Guid.NewGuid().ToString(), name = x.ToString(), campusId = campusId });
  583. //});
  584. //tempShool.period = periods;
  585. tempShool.size = !string.IsNullOrEmpty($"{size}") ? int.Parse($"{size}") : tempShool.size;
  586. tempShool.scale = !string.IsNullOrEmpty($"{scale}") ? int.Parse($"{scale}") : tempShool.scale;
  587. tempShool.picture = $"{picture}";
  588. tempShool.type = int.Parse($"{_type}");
  589. tempShool.name = $"{schoolName}";
  590. tempShool.areaId = $"{areaId}";
  591. tempShool.standard = $"{standard}";
  592. //修改学校
  593. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(tempShool, tempShool.id, new PartitionKey("Base"));
  594. //修改学校教师关联的信息
  595. string sql = $"SELECT distinct value(c) FROM c join A1 in c.schools where A1.schoolId='{tempShool.id}'";
  596. List<Teacher> teachers = new List<Teacher>();
  597. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
  598. {
  599. teachers.Add(item);
  600. }
  601. foreach (var item in teachers)
  602. {
  603. Teacher.TeacherSchool teacherSchool = item.schools.Find(x => x.schoolId.Equals(tempShool.id));
  604. if (teacherSchool != null)
  605. {
  606. teacherSchool.name = tempShool.name;
  607. teacherSchool.picture = tempShool.picture;
  608. teacherSchool.areaId = tempShool.areaId;
  609. }
  610. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(item, item.id, new PartitionKey($"Base"));
  611. }
  612. //修改学校顾问
  613. string sqlTxt = $"SELECT value(c) From c WHERE ARRAY_CONTAINS(c.roles,'assist',true)";
  614. List<SchoolTeacher> schoolTeachers = new List<SchoolTeacher>();
  615. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<SchoolTeacher>(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{tempShool.id}") }))
  616. {
  617. if (!assistId.Contains(item.id))
  618. {
  619. if (item.roles.Contains("assist"))
  620. {
  621. item.roles.Remove("assist");
  622. if (item.roles.Count > 0)
  623. {
  624. await cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<SchoolTeacher>(item, item.id, new PartitionKey(item.code));
  625. }
  626. else
  627. {
  628. await cosmosClient.GetContainer("TEAMModelOS", "School").DeleteItemAsync<SchoolTeacher>(item.id, new PartitionKey(item.code));
  629. }
  630. }
  631. }
  632. }
  633. if (assistId.Count > 0)
  634. {
  635. foreach (var itemTeacher in assistId)
  636. {
  637. Teacher tempTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>($"{itemTeacher}", new PartitionKey("Base"));
  638. if (tempTeacher != null)
  639. {
  640. var haveTeacher = tempTeacher.schools.Find(x => x.schoolId.Equals($"{_schoolId}"));
  641. if (haveTeacher != null)
  642. {
  643. //查询该教师是否存在该校
  644. SchoolTeacher schoolTeacher = null;
  645. try
  646. {
  647. schoolTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<SchoolTeacher>($"{itemTeacher}", new PartitionKey($"Teacher-{tempShool.id}"));
  648. }
  649. catch
  650. {
  651. }
  652. if (schoolTeacher != null)
  653. {
  654. if (!schoolTeacher.roles.Contains("assist"))
  655. {
  656. schoolTeacher.roles.Add("assist");
  657. //添加顾问权限
  658. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<SchoolTeacher>(schoolTeacher, schoolTeacher.id, new PartitionKey($"Teacher-{tempShool.id}"));
  659. }
  660. }
  661. else
  662. {
  663. SchoolTeacher addSchoolTeacher = new SchoolTeacher
  664. {
  665. id = itemTeacher,
  666. code = $"Teacher-{tempShool.id}",
  667. pk = "Teacher",
  668. status = "join",
  669. roles = new List<string>() { "assist" },
  670. name = tempTeacher.name,
  671. job = $"{tempShool.name}-顾问",
  672. size = 0,
  673. createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
  674. };
  675. //添加学校顾问
  676. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(addSchoolTeacher, new PartitionKey($"Teacher-{tempShool.id}"));
  677. }
  678. }
  679. else
  680. {
  681. Teacher.TeacherSchool teacherSchool = new Teacher.TeacherSchool
  682. {
  683. schoolId = tempShool.id,
  684. name = tempShool.name,
  685. status = "join",
  686. time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
  687. picture = tempShool.picture,
  688. areaId = tempShool.areaId
  689. };
  690. tempTeacher.schools.Add(teacherSchool);
  691. //给醍摩豆顾问添加学校
  692. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(tempTeacher, tempTeacher.id, new PartitionKey($"Base"));
  693. //不存在则在原来的基础上添加顾问角色
  694. SchoolTeacher addSchoolTeacher = new SchoolTeacher
  695. {
  696. id = itemTeacher,
  697. code = $"Teacher-{tempShool.id}",
  698. pk = "Teacher",
  699. status = "join",
  700. roles = new List<string>() { "assist" },
  701. name = tempTeacher.name,
  702. job = $"{tempShool.name}-顾问",
  703. size = 0,
  704. createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
  705. };
  706. //添加学校学校顾问
  707. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(addSchoolTeacher, new PartitionKey($"Teacher-{tempShool.id}"));
  708. }
  709. }
  710. }
  711. }
  712. }
  713. //保存操作记录
  714. //await _azureStorage.SaveBILog("school-update", $"{_tmdName}【{_tmdId}】修改学校功能,修改的学校:{_schoolId},{_type},{picture},{size},{string.Join("|", assistId.ToArray())}", _dingDing, httpContext: HttpContext);
  715. await BIAzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "school-update", $"{_tmdName}【{_tmdId}】修改学校功能,修改的学校:{_schoolId},{_type},{picture},{size},{string.Join("|", assistId.ToArray())}", _dingDing, httpContext: HttpContext);
  716. return Ok(new { state = 200 });
  717. }
  718. catch (Exception ex)
  719. {
  720. await _dingDing.SendBotMsg($"BI, {_option.Location} /batchschool/upd-schoolassist \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  721. return BadRequest();
  722. }
  723. }
  724. /// <summary>
  725. /// 查询区域的学校
  726. /// </summary>
  727. /// <param name="jsonElement"></param>
  728. /// <returns></returns>
  729. [ProducesDefaultResponseType]
  730. [HttpPost("get-schooldist")]
  731. public async Task<IActionResult> GetSchoolDist(JsonElement jsonElement)
  732. {
  733. try
  734. {
  735. if (!jsonElement.TryGetProperty("dist", out JsonElement _dist)) return BadRequest();
  736. jsonElement.TryGetProperty("site", out JsonElement site);
  737. var cosmosClient = _azureCosmos.GetCosmosClient();
  738. if ($"{site}".Equals(BIConst.GlobalSite))
  739. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
  740. string sqltxt = $"SELECT * FROM c where c.dist='{_dist}'";
  741. List<School> schools = new List<School>();
  742. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<School>(queryText: sqltxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  743. {
  744. schools.Add(item);
  745. }
  746. return Ok(new { state = 200, schools });
  747. }
  748. catch (Exception ex)
  749. {
  750. await _dingDing.SendBotMsg($"BI,{_option.Location} /batchschool/get-schooldist \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  751. return BadRequest();
  752. }
  753. }
  754. /// <summary>
  755. /// 分页学校和顾问信息
  756. /// </summary>
  757. /// <param name="jsonElement"></param>
  758. /// <returns></returns>
  759. [HttpPost("get-schools")]
  760. public async Task<IActionResult> GetSchools(JsonElement jsonElement)
  761. {
  762. //List<School> schools = new List<School>();
  763. List<AssistSchool> schoolAssists = new List<AssistSchool>();
  764. if (!jsonElement.TryGetProperty("endPosition", out JsonElement endPosition)) return BadRequest();
  765. if (!jsonElement.TryGetProperty("pageSize", out JsonElement pageSize)) return BadRequest();
  766. jsonElement.TryGetProperty("site", out JsonElement site);
  767. var cosmosClient = _azureCosmos.GetCosmosClient();
  768. if ($"{site}".Equals(BIConst.GlobalSite))
  769. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.GlobalSite);
  770. string sqltxt = $"SELECT * FROM c order by c.id offset {endPosition} limit {pageSize}";
  771. await foreach (var itemSchool in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<School>(queryText: sqltxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  772. {
  773. AssistSchool schoolAssist = new()
  774. {
  775. id = itemSchool.id,
  776. code = itemSchool.code,
  777. schoolCode = itemSchool.schoolCode,
  778. name = itemSchool.name,
  779. region = itemSchool.region,
  780. province = itemSchool.province,
  781. city = itemSchool.city,
  782. dist = itemSchool.dist,
  783. size = itemSchool.size,
  784. address = itemSchool.address,
  785. picture = itemSchool.picture,
  786. type = itemSchool.type,
  787. scale = itemSchool.scale,
  788. areaId = itemSchool.areaId,
  789. standard = itemSchool.standard
  790. };
  791. schoolAssist.assists = await CommonFind.FindSchoolRoles(cosmosClient, itemSchool.id, "assist");
  792. //List<Assist> assists = new List<Assist>();
  793. ////查询学校的顾问
  794. //string managerSql = $"SELECT DISTINCT REPLACE(c.code, 'Teacher-', '') AS schoolId, c.id, c.name FROM c WHERE ARRAY_CONTAINS(c.roles, 'assist', true) AND c.pk = 'Teacher' AND c.status = 'join' AND c.code = 'Teacher-{itemSchool.id}'";
  795. //var cosmosClent = _azureCosmos.GetCosmosClient();
  796. //await foreach (var item in cosmosClent.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: managerSql, requestOptions: new QueryRequestOptions() { }))
  797. //{
  798. // using var json = await JsonDocument.ParseAsync(item.ContentStream);
  799. // foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  800. // {
  801. // Assist assist = new Assist
  802. // {
  803. // tmdId = obj.GetProperty("id").GetString(),
  804. // tmdName = obj.GetProperty("name").GetString()
  805. // };
  806. // assists.Add(assist);
  807. // }
  808. //}
  809. //schoolAssist.assists = assists;
  810. schoolAssists.Add(schoolAssist);
  811. }
  812. return Ok(new { state = 200, schoolAssists });
  813. }
  814. #region 预设学校基础信息 多语言
  815. /// <summary>
  816. /// 预设学校基础信息 多语言
  817. /// </summary>
  818. /// <param name="period"></param>
  819. /// <param name="Language"></param>
  820. /// <param name="campusId"></param>
  821. /// <returns></returns>
  822. public List<Period> PresetSchoolPeriod(List<string> period, string Language, string campusId)
  823. {
  824. var builder = $"{_environment.ContentRootPath}/JsonFile/Preset/LangSchoolConfig.json";
  825. StreamReader streamReader = new StreamReader(new FileStream(builder, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8);
  826. StringBuilder stringBuilder = new StringBuilder();
  827. string text;
  828. while ((text = streamReader.ReadLine()) != null)
  829. {
  830. stringBuilder.Append(text.ToString());
  831. }
  832. streamReader.Close();
  833. string input = stringBuilder.ToString();
  834. List<SchoolConfig> schoolConfigs = input.ToObject<List<SchoolConfig>>();
  835. SchoolConfig schoolConfig = schoolConfigs.Find(x => x.Lang.Contains($"{Language}"));
  836. if (schoolConfig == null)
  837. {
  838. if (Language.Contains("en"))
  839. schoolConfig = schoolConfigs.Find(x => x.Lang.Contains("en-US"));
  840. else
  841. schoolConfig = schoolConfigs.Find(x => x.Lang.Contains("zh-CN"));
  842. }
  843. List<Period> periods = new List<Period>();
  844. period.ForEach(x =>
  845. {
  846. periods.Add(new Period
  847. {
  848. id = Guid.NewGuid().ToString(),
  849. name = x,
  850. campusId = campusId,
  851. 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() },
  852. 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() } },
  853. subjects = new List<Subject>() {
  854. new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[0].name,type=schoolConfig.PresetSubject[0].type },
  855. new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[1].name,type=schoolConfig.PresetSubject[1].type },
  856. new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[2].name,type=schoolConfig.PresetSubject[2].type }
  857. },
  858. grades = schoolConfig.grades,
  859. analysis = new Analysis()
  860. {
  861. type = new List<ExamSimple>() { new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[0].name },
  862. new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[1].name },
  863. new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[2].name },
  864. new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[3].name } },
  865. income = schoolConfig.PresetExam[0].income,
  866. eugenics = schoolConfig.PresetExam[0].eugenics,
  867. touch = schoolConfig.PresetExam[0].touch
  868. }
  869. });
  870. });
  871. return periods;
  872. }
  873. public record SchoolConfig
  874. {
  875. public string Lang { get; set; }
  876. public List<semester> semester { get; set; }
  877. public List<string> grades { get; set; }
  878. public List<PresetSubject> PresetSubject { get; set; }
  879. public List<PresetExam> PresetExam { get; set; }
  880. }
  881. public record semester
  882. {
  883. public string id { get; set; } = Guid.NewGuid().ToString();
  884. public string term { get; set; }
  885. public int start { get; set; }
  886. public int month { get; set; }
  887. public int day { get; set; }
  888. }
  889. public record PresetSubject
  890. {
  891. public string id { get; set; } = Guid.NewGuid().ToString();
  892. public string name { get; set; }
  893. public int type { get; set; }
  894. }
  895. public record PresetExam
  896. {
  897. public List<StudyType> type { get; set; }
  898. public int income { get; set; }
  899. public int eugenics { get; set; }
  900. public int touch { get; set; }
  901. }
  902. public record StudyType
  903. {
  904. public string id { get; set; } = Guid.NewGuid().ToString();
  905. public string name { get; set; }
  906. }
  907. #endregion
  908. //public class SchoolAssist
  909. //{
  910. // public string id { get; set; }
  911. // public string code { get; set; }
  912. // public string schoolCode { get; set; }
  913. // public string name { get; set; }
  914. // public string region { get; set; }
  915. // public string province { get; set; }
  916. // public string city { get; set; }
  917. // public string dist { get; set; }
  918. // public int size { get; set; }
  919. // public string address { get; set; }
  920. // public string picture { get; set; }
  921. // public int type { get; set; }
  922. // public int scale { get; set; }
  923. // public string standard { get; set; }
  924. // public string areaId { get; set; }
  925. // public List<SchoolTeacherRoles> assists { get; set; }
  926. // public int serial { get; set; } //软体
  927. // public int service { get; set; } //服务
  928. // public int hard { get; set; } //硬体
  929. // //public List<SchoolProductSumData> serial { get; set; } //软体
  930. // //public List<SchoolProductSumData> service { get; set; } //服务
  931. // //public List<SchoolProductSumDataHard> hard { get; set; } //硬体
  932. //}
  933. /// <summary>
  934. /// 创建多个学校实体
  935. /// </summary>
  936. public record FoundSchools()
  937. {
  938. /// <summary>
  939. /// 语系
  940. /// </summary>
  941. public string lang { get; set; }
  942. /// <summary>
  943. /// 站点
  944. /// </summary>
  945. public string site { get; set; }
  946. /// <summary>
  947. /// 批量创校的数据结构
  948. /// </summary>
  949. public List<BISchool> biSchools { get; set; } = new List<BISchool>();
  950. }
  951. /// <summary>
  952. /// 批量创校的数据结构
  953. /// </summary>
  954. public record BISchool()
  955. {
  956. /// <summary>
  957. /// 学校名称
  958. /// </summary>
  959. public string name { get; set; }
  960. /// <summary>
  961. /// 学校管理员
  962. /// </summary>
  963. public string admin { get; set; }
  964. /// <summary>
  965. /// 学校的学段
  966. /// </summary>
  967. public List<string> period { get; set; }
  968. /// <summary>
  969. /// 学校空间大小
  970. /// </summary>
  971. public int size { get; set; }
  972. /// <summary>
  973. /// 地区
  974. /// </summary>
  975. public string region { get; set; }
  976. /// <summary>
  977. /// 省份
  978. /// </summary>
  979. public string province { get; set; }
  980. /// <summary>
  981. /// 城市
  982. /// </summary>
  983. public string city { get; set; }
  984. /// <summary>
  985. /// 县,区,郡
  986. /// </summary>
  987. public string dist { get; set; }
  988. /// <summary>
  989. /// 学校详细地址
  990. /// </summary>
  991. public string address { get; set; }
  992. /// <summary>
  993. /// 学校类型
  994. /// </summary>
  995. public int type { get; set; }
  996. /// <summary>
  997. /// 区域ID
  998. /// </summary>
  999. public string areaId { get; set; }
  1000. /// <summary>
  1001. /// 区域标准
  1002. /// </summary>
  1003. public string standard { get; set; }
  1004. }
  1005. public record Exist()
  1006. {
  1007. public string ID { get; set; }
  1008. public string name { get; set; }
  1009. }
  1010. }
  1011. }