BatchSchoolController.cs 59 KB

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