BatchSchoolController.cs 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506
  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. using Pipelines.Sockets.Unofficial.Arenas;
  33. using Microsoft.Identity.Client;
  34. using TEAMModelOS.SDK.Models.Dtos;
  35. using DocumentFormat.OpenXml.Spreadsheet;
  36. using DocumentFormat.OpenXml.Wordprocessing;
  37. namespace TEAMModelBI.Controllers.BISchool
  38. {
  39. [Route("batchschool")]
  40. [ApiController]
  41. public class BatchSchoolController : ControllerBase
  42. {
  43. private readonly AzureCosmosFactory _azureCosmos;
  44. private readonly DingDing _dingDing;
  45. private readonly Option _option;
  46. private readonly AzureStorageFactory _azureStorage;
  47. private readonly IWebHostEnvironment _environment; //读取文件
  48. private readonly IHttpClientFactory _http;
  49. //读取配置信息
  50. private readonly IConfiguration _configuration;
  51. private readonly CoreAPIHttpService _coreAPIHttpService;
  52. public BatchSchoolController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IWebHostEnvironment hostingEnvironment, IConfiguration configuration, IHttpClientFactory http, CoreAPIHttpService coreAPIHttpService)
  53. {
  54. _azureCosmos = azureCosmos;
  55. _dingDing = dingDing;
  56. _azureStorage = azureStorage;
  57. _option = option?.Value;
  58. _environment = hostingEnvironment;
  59. _configuration = configuration;
  60. _http = http;
  61. _coreAPIHttpService = coreAPIHttpService;
  62. }
  63. /// <summary>
  64. /// 获取BI权限列表 //已对接
  65. /// </summary>
  66. /// <returns></returns>
  67. [ProducesDefaultResponseType]
  68. [HttpPost("get-teacher-authoritybilist")]
  69. public async Task<IActionResult> GetAuthorityBIList(JsonElement jsonElement)
  70. {
  71. //jsonElement.TryGetProperty("site", out JsonElement site);
  72. Dictionary<string, object> dic = new() { { "PartitionKey", "authority-bi" } };
  73. var table = _azureStorage.GetCloudTableClient().GetTableReference("SchoolSetting");
  74. ////分开部署,就不需要,一站多用时,取消注释
  75. //if ($"{site}".Equals(BIConst.Global))
  76. // table = _azureStorage.GetCloudTableClient(BIConst.Global).GetTableReference("SchoolSetting");
  77. List<Authority> authorityBIList = await table.FindListByDict<Authority>(dic);
  78. return Ok(new { authorityBIList });
  79. }
  80. public async Task<IActionResult> GetSchoolCode(JsonElement jsonElement)
  81. {
  82. if (!jsonElement.TryGetProperty("schools", out JsonElement schools)) return BadRequest();
  83. var cosmosClient = _azureCosmos.GetCosmosClient();
  84. List<CreateSchoolInfo> cSchools = schools.ToObject<List<CreateSchoolInfo>>();
  85. List<CreateSchoolInfo> createScInfo = new();
  86. foreach (var item in cSchools)
  87. {
  88. CreateSchoolInfo createSchoolInfo = item;
  89. //生成学校ID
  90. bool tempStaus = true;
  91. do
  92. {
  93. createSchoolInfo = await SchoolCode.GenerateSchoolCode(createSchoolInfo, _dingDing, _environment);
  94. var schoolStatu = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{createSchoolInfo.id}", new PartitionKey($"Base"));
  95. if (schoolStatu.Status != 200) tempStaus = false;
  96. else createSchoolInfo.createCount = createSchoolInfo.createCount >= 3 ? createSchoolInfo.createCount = 3 : createSchoolInfo.createCount += 1;
  97. } while (tempStaus);
  98. createScInfo.Add(createSchoolInfo);
  99. }
  100. return Ok(new { state = RespondCode.Ok });
  101. }
  102. /// <summary>
  103. /// 批量创校 //已对接
  104. /// </summary>
  105. /// <param name="school"></param>
  106. /// <returns></returns>
  107. [ProducesDefaultResponseType]
  108. [AuthToken(Roles = "admin,rdc")]
  109. [HttpPost("batch-school")]
  110. public async Task<IActionResult> BatchCreateSchool(FoundSchools foundSchools)
  111. {
  112. try
  113. {
  114. var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  115. List<BISchool> schools = new();
  116. List<BISchool> userScs = new();
  117. List<BISchool> cutArea = new();
  118. List<string> upSc = new();
  119. StringBuilder stringBuilder = new($"{_tmdName}【{_tmdId}】使用批量创校功能:");
  120. StringBuilder noticeDD = new(); //创校信息通知
  121. var cosmosClient = _azureCosmos.GetCosmosClient();
  122. var tableClient = _azureStorage.GetCloudTableClient();
  123. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  124. //if (BIConst.Global.Equals($"{foundSchools.site}"))
  125. //{
  126. // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  127. // tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
  128. // blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
  129. //}
  130. if (foundSchools.biSchools.Count > 0)
  131. {
  132. #region 新版直接创建
  133. foreach (BISchool bischool in foundSchools.biSchools)
  134. {
  135. Area area = null;
  136. //查询区是否存在
  137. var respAreaId = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{bischool.areaId}", new PartitionKey("Base-Area"));
  138. if (respAreaId.Status == 200)
  139. {
  140. using var areaBase = await JsonDocument.ParseAsync(respAreaId.ContentStream);
  141. area = areaBase.ToObject<Area>();
  142. }
  143. CreateSchoolInfo createSchoolInfo = new CreateSchoolInfo()
  144. {
  145. province = bischool.province,
  146. id = "",
  147. name = bischool.name,
  148. city = bischool.city,
  149. aname = "",
  150. createCount = 0,
  151. };
  152. //生成学校ID
  153. bool tempStaus = true;
  154. do
  155. {
  156. createSchoolInfo = await SchoolCode.GenerateSchoolCode(createSchoolInfo, _dingDing, _environment);
  157. var schoolStatu = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{createSchoolInfo.id}", new PartitionKey($"Base"));
  158. if (schoolStatu.Status != 200) tempStaus = false;
  159. else createSchoolInfo.createCount = createSchoolInfo.createCount >= 3 ? createSchoolInfo.createCount = 3 : createSchoolInfo.createCount += 1;
  160. } while (tempStaus);
  161. if (createSchoolInfo.id != null)
  162. {
  163. string campusId = Guid.NewGuid().ToString();
  164. School upSchool = new()
  165. {
  166. id = createSchoolInfo.id,
  167. name = bischool.name,
  168. size = bischool.size == 0 ? 100 : bischool.size,
  169. code = "Base",
  170. campuses = new List<Campus> { new Campus { name = bischool.name, id = campusId } },
  171. region = bischool.region,
  172. province = bischool.province,
  173. city = bischool.city,
  174. dist = bischool.dist,
  175. address = bischool.address,
  176. picture = "https://teammodelstorage.blob.core.chinacloudapi.cn/0-public/school/bbf54fb3-3fc8-43ae-a358-107281c174cc.png",
  177. timeZone = new TEAMModelOS.SDK.Models.TimeZone { label = "(UTC+08:00) 北京,重庆,香港特别行政区,乌鲁木齐", value = "+08:00" },
  178. type = string.IsNullOrEmpty(bischool.type.ToString()) ? 1 : bischool.type,
  179. pk = "School",
  180. ttl = -1,
  181. areaId = area == null ? "" : area.id,
  182. standard = area == null ? "" : area.standard,
  183. schoolCode = createSchoolInfo.id,
  184. period = PresetSchoolPeriod(bischool.period, foundSchools.lang, campusId),
  185. scale = bischool.size >= 300 ? 500 : 0,
  186. createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
  187. };
  188. stringBuilder.Append($"创建学校:{upSchool.name}【{upSchool.id}】");
  189. noticeDD.Append($"{upSchool.name}【{upSchool.id}】 \r 学校管理员信息:");
  190. upSc.Add(upSchool.id);
  191. //创建学校
  192. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<School>(upSchool, new PartitionKey(upSchool.code));
  193. var content = new StringContent(bischool.admin.ToArray().ToJsonString(), Encoding.UTF8, "application/json");
  194. string json = await _coreAPIHttpService.GetUserInfos(content);
  195. List<TmdUserinfo> tmdInfos = json.ToObject<List<TmdUserinfo>>();
  196. foreach (var tmdIndo in tmdInfos)
  197. {
  198. Teacher teacher = new();
  199. var resTeache = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemStreamAsync($"{tmdIndo.id}", new PartitionKey("Base"));
  200. if (resTeache.Status == 200)
  201. {
  202. using var tchJson = await JsonDocument.ParseAsync(resTeache.ContentStream);
  203. teacher = tchJson.ToObject<Teacher>();
  204. //教师存在,在该教师信息中添加要管理的学校信息
  205. 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() });
  206. //await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, coreUser.id, new PartitionKey("Base"));
  207. SchoolTeacher schoolTeacher = new()
  208. {
  209. id = tmdIndo.id,
  210. code = $"Teacher-{createSchoolInfo.id}",
  211. roles = new List<string> { "admin" },
  212. job = "管理员",
  213. name = teacher.name,
  214. picture = teacher.picture,
  215. status = "join",
  216. createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
  217. pk = "Teacher",
  218. ttl = -1
  219. };
  220. stringBuilder.Append($"【基础:{schoolTeacher.name}【{schoolTeacher.id}】,权限:{string.Join(",", schoolTeacher.roles)}】");
  221. noticeDD.Append($"{schoolTeacher.name}【{schoolTeacher.id}】");
  222. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
  223. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey(schoolTeacher.code));
  224. }
  225. else
  226. {
  227. //不存在 新建教师和新建要管理的学校信息
  228. Teacher addteacher = new()
  229. {
  230. id = tmdIndo.id,
  231. pk = "Base",
  232. code = "Base",
  233. name = $"{tmdIndo.name}",
  234. picture = $"{tmdIndo.picture}",
  235. //创建账号并第一次登录IES5则默认赠送1G
  236. size = 1,
  237. defaultSchool = createSchoolInfo.id,
  238. createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
  239. schools = new List<Teacher.TeacherSchool>() { new Teacher.TeacherSchool { schoolId = createSchoolInfo.id, name = bischool.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() } }
  240. };
  241. stringBuilder.Append($"【没有该教师基础信息,创建的教师基本信息:{addteacher.name}【{addteacher.id}】");
  242. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(addteacher, new PartitionKey("Base"));
  243. SchoolTeacher schoolTeacher = new()
  244. {
  245. id = tmdIndo.id,
  246. code = $"Teacher-{createSchoolInfo.id}",
  247. roles = new List<string> { "admin" },
  248. job = "管理员",
  249. name = $"{tmdIndo.name}",
  250. picture = "",
  251. status = "join",
  252. createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
  253. pk = "Teacher",
  254. ttl = -1
  255. };
  256. stringBuilder.Append($"权限:{string.Join(",", schoolTeacher.roles)}】");
  257. noticeDD.Append($"{schoolTeacher.name}【{schoolTeacher.id}】");
  258. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey(schoolTeacher.code));
  259. }
  260. }
  261. }
  262. }
  263. #endregion
  264. #region 旧版先检测 在创建
  265. //foreach (BISchool bischool in foundSchools.biSchools)
  266. //{
  267. // List<string> scName = new();
  268. // //查询学校名称是否全字段匹配
  269. // 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") }))
  270. // {
  271. // scName.Add(item);
  272. // }
  273. // Area area = null;
  274. // //查询区是否存在
  275. // var respAreaId = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{bischool.areaId}", new PartitionKey("Base-Area"));
  276. // if (respAreaId.Status == 200)
  277. // {
  278. // using var areaBase = await JsonDocument.ParseAsync(respAreaId.ContentStream);
  279. // area = areaBase.ToObject<Area>();
  280. // }
  281. // bool isSYNCArea = false;
  282. // //查询去是否同步省平台
  283. // var responseSet = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{bischool.areaId}", new PartitionKey("AreaSetting"));
  284. // if (responseSet.Status == 200)
  285. // {
  286. // using var fileJson = await JsonDocument.ParseAsync(responseSet.ContentStream);
  287. // AreaSetting delSet = fileJson.ToObject<AreaSetting>();
  288. // if (!string.IsNullOrEmpty(delSet.accessConfig))
  289. // isSYNCArea = true;
  290. // }
  291. // if (scName.Count <= 0)
  292. // {
  293. // if (isSYNCArea == false)
  294. // {
  295. // var coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", $"{bischool.admin}" } }, _option.Location, _configuration);
  296. // if (coreUser != null && coreUser.id != null)
  297. // {
  298. // CreateSchoolInfo createSchoolInfo = new CreateSchoolInfo()
  299. // {
  300. // province = bischool.province,
  301. // id = "",
  302. // name = bischool.name,
  303. // city = bischool.city,
  304. // aname = "",
  305. // createCount = 0,
  306. // };
  307. // //生成学校ID
  308. // bool tempStaus = true;
  309. // do
  310. // {
  311. // createSchoolInfo = await SchoolCode.GenerateSchoolCode(createSchoolInfo, _dingDing, _environment);
  312. // var schoolStatu = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{createSchoolInfo.id}", new PartitionKey($"Base"));
  313. // if (schoolStatu.Status != 200) tempStaus = false;
  314. // else createSchoolInfo.createCount = createSchoolInfo.createCount >= 3 ? createSchoolInfo.createCount = 3 : createSchoolInfo.createCount += 1;
  315. // } while (tempStaus);
  316. // if (createSchoolInfo.id != null)
  317. // {
  318. // string campusId = Guid.NewGuid().ToString();
  319. // School upSchool = new()
  320. // {
  321. // id = createSchoolInfo.id,
  322. // name = bischool.name,
  323. // size = bischool.size == 0 ? 100 : bischool.size,
  324. // code = "Base",
  325. // campuses = new List<Campus> { new Campus { name = bischool.name, id = campusId } },
  326. // region = bischool.region,
  327. // province = bischool.province,
  328. // city = bischool.city,
  329. // dist = bischool.dist,
  330. // address = bischool.address,
  331. // picture = "https://teammodelstorage.blob.core.chinacloudapi.cn/0-public/school/bbf54fb3-3fc8-43ae-a358-107281c174cc.png",
  332. // timeZone = new TEAMModelOS.SDK.Models.TimeZone { label = "(UTC+08:00) 北京,重庆,香港特别行政区,乌鲁木齐", value = "+08:00" },
  333. // type = string.IsNullOrEmpty(bischool.type.ToString()) ? 1 : bischool.type,
  334. // pk = "School",
  335. // ttl = -1,
  336. // areaId = area == null ? "" : area.id,
  337. // standard = area == null ? "" : area.standard,
  338. // schoolCode = createSchoolInfo.id,
  339. // period = PresetSchoolPeriod(bischool.period, foundSchools.lang, campusId),
  340. // scale = bischool.size >= 300 ? 500 : 0,
  341. // createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
  342. // };
  343. // stringBuilder.Append($"创建学校:{upSchool.name}【{upSchool.id}】");
  344. // noticeDD.Append($"【ID:{upSchool.id}|名称:{upSchool.name}】 ");
  345. // upSc.Add(upSchool.id);
  346. // //创建学校
  347. // await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<School>(upSchool, new PartitionKey(upSchool.code));
  348. // //创建学校管理员
  349. // Teacher teacher = null;
  350. // var resTeache = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemStreamAsync($"{coreUser.id}", new PartitionKey("Base"));
  351. // if (resTeache.Status == 200)
  352. // {
  353. // using var tchJson = await JsonDocument.ParseAsync(resTeache.ContentStream);
  354. // teacher = tchJson.ToObject<Teacher>();
  355. // //教师存在,在该教师信息中添加要管理的学校信息
  356. // 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() });
  357. // //await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, coreUser.id, new PartitionKey("Base"));
  358. // SchoolTeacher schoolTeacher = new()
  359. // {
  360. // id = coreUser.id,
  361. // code = $"Teacher-{createSchoolInfo.id}",
  362. // roles = new List<string> { "admin", "teacher" },
  363. // job = "管理员",
  364. // name = teacher.name,
  365. // picture = teacher.picture,
  366. // status = "join",
  367. // createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
  368. // pk = "Teacher",
  369. // ttl = -1
  370. // };
  371. // stringBuilder.Append($"教师信息:{schoolTeacher.name}【{schoolTeacher.id}】,教师权限:{string.Join(",", schoolTeacher.roles)}");
  372. // await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
  373. // await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey(schoolTeacher.code));
  374. // }
  375. // else
  376. // {
  377. // //不存在 新建教师和新建要管理的学校信息
  378. // Teacher addteacher = new()
  379. // {
  380. // id = coreUser.id,
  381. // pk = "Base",
  382. // code = "Base",
  383. // name = $"{coreUser.name}",
  384. // picture = $"{coreUser.picture}",
  385. // //创建账号并第一次登录IES5则默认赠送1G
  386. // size = 1,
  387. // defaultSchool = createSchoolInfo.id,
  388. // createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
  389. // schools = new List<Teacher.TeacherSchool>() { new Teacher.TeacherSchool { schoolId = createSchoolInfo.id, name = bischool.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() } }
  390. // };
  391. // stringBuilder.Append($"没有该教师信息创建的教师信息:{addteacher.name}【{addteacher.id}】");
  392. // await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(addteacher, new PartitionKey("Base"));
  393. // SchoolTeacher schoolTeacher = new()
  394. // {
  395. // id = coreUser.id,
  396. // code = $"Teacher-{createSchoolInfo.id}",
  397. // roles = new List<string> { "admin", "teacher" },
  398. // job = "管理员",
  399. // name = $"{coreUser.name}",
  400. // picture = "",
  401. // status = "join",
  402. // createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
  403. // pk = "Teacher",
  404. // ttl = -1
  405. // };
  406. // stringBuilder.Append($"教师权限:{string.Join(",", schoolTeacher.roles)}");
  407. // await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey(schoolTeacher.code));
  408. // }
  409. // }
  410. // }
  411. // else userScs.Add(bischool);
  412. // }
  413. // else cutArea.Add(bischool);
  414. // }
  415. // else schools.Add(bischool);
  416. //}
  417. #endregion
  418. }
  419. else return Ok(new { state = 1, message = "创校信息为空" });
  420. if (upSc.Count > 1)
  421. await _dingDing.SendBotMsg($"BI,{_option.Location} \n 批量建校信息:{noticeDD}", GroupNames.成都开发測試群組);
  422. else if(upSc.Count == 1)
  423. await _dingDing.SendBotMsg($"BI,{_option.Location} \n 单个建校信息:{noticeDD}", GroupNames.成都开发測試群組);
  424. //v2通知
  425. Teacher targetTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<Teacher>($"1", new PartitionKey($"Base"));
  426. _coreAPIHttpService.PushNotify(new List<IdNameCode> { new IdNameCode { id = targetTeacher.id, name = targetTeacher.name, code = targetTeacher.lang } }, "transfer-admin_school", Constant.NotifyType_IES5_Management, new Dictionary<string, object> { { "tmdname", "账号名称" }, { "schooName", "学校名称" }, { "schoolId", $"学校id" }, { "tmdid", "账号id" } }, _option.Location, _configuration, _dingDing, _environment.ContentRootPath);
  427. //保存操作记录
  428. await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "school-batchAdd", stringBuilder?.ToString(), _dingDing, httpContext: HttpContext);
  429. if (schools.Count == foundSchools.biSchools.Count || userScs.Count == foundSchools.biSchools.Count)
  430. return Ok(new { state = RespondCode.CreateFailed, message = "已有部分学校批量创建成功;学校已经重复/学校信息有误!请检查学校信息!", schools, userScs });
  431. else
  432. {
  433. if (schools.Count > 0 || userScs.Count > 0 || cutArea.Count > 0)
  434. return Ok(new { state = RespondCode.Created, message = "已有部分学校批量创建成功;学校已经重复/学校信息有误/区域已在研修不能加区!请检查学校信息!", schools, userScs, cutArea });
  435. else
  436. return Ok(new { state = RespondCode.Ok, message = "批量创校已全部完成" });
  437. }
  438. }
  439. catch (Exception ex)
  440. {
  441. await _dingDing.SendBotMsg($"BI,{_option.Location} /batchschool/batch-school \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  442. return BadRequest();
  443. }
  444. }
  445. /// <summary>
  446. /// 依据学校编号查询学校信息;若是没有传学校编号,则查询所有学校信息 //已对接
  447. /// </summary>
  448. /// <param name="jsonElement"></param>
  449. /// <returns></returns>
  450. [ProducesDefaultResponseType]
  451. [HttpPost("get-schoolsinfo")]
  452. public async Task<IActionResult> GetSchoolsInfo(JsonElement jsonElement)
  453. {
  454. try
  455. {
  456. jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
  457. jsonElement.TryGetProperty("scId", out JsonElement scId);
  458. jsonElement.TryGetProperty("name", out JsonElement name);
  459. jsonElement.TryGetProperty("order", out JsonElement order);
  460. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  461. var cosmosClient = _azureCosmos.GetCosmosClient();
  462. ////分开部署,就不需要,一站多用时,取消注释
  463. //if ($"{site}".Equals(BIConst.Global))
  464. // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  465. int scCnt = 0;
  466. int? pageSize = 100; //默认不指定返回大小
  467. string continuationToken = string.Empty; //返给前端分页token
  468. string pageToken = default;//接受前端的分页Tolen
  469. bool iscontinuation = false;//是否需要进行分页查询,默认不分页
  470. List<AssistSchool> schoolAssists = new(); //返回学校列表集合
  471. List<string> schoolIds = new();
  472. 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 ");
  473. scCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", "select value(count(c.id)) from c", "Base");
  474. if (jsonElement.TryGetProperty("pageSize", out JsonElement jsonPageSize))
  475. {
  476. if (!jsonPageSize.ValueKind.Equals(JsonValueKind.Undefined) && !jsonPageSize.ValueKind.Equals(JsonValueKind.Null) && jsonPageSize.TryGetInt32(out int tempPageSize))
  477. {
  478. pageSize = tempPageSize;
  479. }
  480. }
  481. if (pageSize != null && pageSize.Value > 0)
  482. {
  483. iscontinuation = true;
  484. }
  485. if (jsonElement.TryGetProperty("contToken", out JsonElement ContToken))
  486. {
  487. pageToken = ContToken.GetString();
  488. }
  489. if (!string.IsNullOrEmpty($"{tmdId}"))
  490. {
  491. schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
  492. }
  493. if (schoolIds.Count > 0)
  494. {
  495. foreach (var id in schoolIds)
  496. {
  497. StringBuilder sqlTxt = 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 where c.id='{id}'");
  498. if ($"{order}".Equals("desc"))
  499. {
  500. sqlTxt.Append(" order by c.createTime desc");
  501. }
  502. await foreach (var itemSchool in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<AssistSchool>(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  503. {
  504. schoolAssists.Add(itemSchool);
  505. }
  506. }
  507. }
  508. else
  509. {
  510. if (!string.IsNullOrEmpty($"{scId}") && string.IsNullOrEmpty($"{name}"))
  511. {
  512. stringBuilder.Append($" where c.id='{scId}'");
  513. }
  514. if (string.IsNullOrEmpty($"{scId}") && !string.IsNullOrEmpty($"{name}"))
  515. {
  516. stringBuilder.Append($" where Contains(c.name,'{name}')");
  517. }
  518. if ($"{order}".Equals("desc"))
  519. {
  520. stringBuilder.Append(" order by c.createTime desc");
  521. }
  522. await foreach (var itemSchool in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: stringBuilder.ToString(), continuationToken: pageToken, requestOptions: new QueryRequestOptions() { MaxItemCount = pageSize, PartitionKey = new PartitionKey("Base") }))
  523. {
  524. using var json = await JsonDocument.ParseAsync(itemSchool.ContentStream);
  525. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetInt16() > 0)
  526. {
  527. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  528. {
  529. schoolAssists.Add(obj.ToObject<AssistSchool>());
  530. }
  531. if (iscontinuation)
  532. {
  533. continuationToken = itemSchool.GetContinuationToken();
  534. break;
  535. }
  536. }
  537. }
  538. }
  539. foreach (var item in schoolAssists)
  540. {
  541. var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(item.id, new PartitionKey("ProductSum"));
  542. if (response.Status == 200)
  543. {
  544. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  545. if (json.RootElement.TryGetProperty("serial", out JsonElement serial) && !serial.ValueKind.Equals(JsonValueKind.Null))
  546. {
  547. item.serial = serial.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
  548. }
  549. if (json.RootElement.TryGetProperty("service", out JsonElement service) && !service.ValueKind.Equals(JsonValueKind.Null))
  550. {
  551. item.service = service.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
  552. }
  553. if (json.RootElement.TryGetProperty("hard", out JsonElement hard) && !hard.ValueKind.Equals(JsonValueKind.Null))
  554. {
  555. item.hard = hard.ToObject<List<SchoolProductSumDataHard>>().Select(x => x.prodCode).ToList();
  556. }
  557. }
  558. item.assists = await CommonFind.FindSchoolRoles(cosmosClient, item.id, "assist");
  559. item.scAdmin = await CommonFind.FindSchoolRoles(cosmosClient, item.id, "admin");
  560. item.lessonCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"select value(count(c.id)) from c ", $"LessonRecord-{item.id}");
  561. }
  562. //schoolAssists.ForEach(async school =>
  563. //{
  564. // var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(school.id, new PartitionKey("ProductSum"));
  565. // if (response.Status == 200)
  566. // {
  567. // using var json = await JsonDocument.ParseAsync(response.ContentStream);
  568. // if (json.RootElement.TryGetProperty("serial", out JsonElement serial) && !serial.ValueKind.Equals(JsonValueKind.Null))
  569. // {
  570. // school.serial = serial.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
  571. // }
  572. // if (json.RootElement.TryGetProperty("service", out JsonElement service) && !service.ValueKind.Equals(JsonValueKind.Null))
  573. // {
  574. // school.service = service.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
  575. // }
  576. // if (json.RootElement.TryGetProperty("hard", out JsonElement hard) && !hard.ValueKind.Equals(JsonValueKind.Null))
  577. // {
  578. // school.hard = hard.ToObject<List<SchoolProductSumDataHard>>().Select(x => x.prodCode).ToList();
  579. // }
  580. // }
  581. // school.assists = await CommonFind.FindSchoolRoles(cosmosClient, school.id, "assist");
  582. // school.lessonCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"select value(count(c.id)) from c ", $"LessonRecord-{school.id}");
  583. //});
  584. return Ok(new { state = 200, scCnt, continuationToken, schoolAssists });
  585. }
  586. catch (Exception ex)
  587. {
  588. await _dingDing.SendBotMsg($"BI,{_option.Location} /batchschool/get-schoolsinfo \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  589. return BadRequest();
  590. }
  591. }
  592. /// <summary>
  593. /// 使用yieId 关键字 本地效率未测出
  594. /// </summary>
  595. /// <param name="cosmosClient"></param>
  596. /// <param name="schoolAssists"></param>
  597. /// <returns></returns>
  598. private async IAsyncEnumerable<List<AssistSchool>> GetSchools(CosmosClient cosmosClient, List<AssistSchool> schoolAssists)
  599. {
  600. List<AssistSchool> tempSchoolAssists = new();
  601. foreach (var temp in schoolAssists)
  602. {
  603. var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(temp.id, new PartitionKey("ProductSum"));
  604. if (response.Status == 200)
  605. {
  606. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  607. if (json.RootElement.TryGetProperty("serial", out JsonElement serial) && !serial.ValueKind.Equals(JsonValueKind.Null))
  608. {
  609. temp.serial = serial.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
  610. }
  611. if (json.RootElement.TryGetProperty("service", out JsonElement service) && !service.ValueKind.Equals(JsonValueKind.Null))
  612. {
  613. temp.service = service.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
  614. }
  615. if (json.RootElement.TryGetProperty("hard", out JsonElement hard) && !hard.ValueKind.Equals(JsonValueKind.Null))
  616. {
  617. temp.hard = hard.ToObject<List<SchoolProductSumDataHard>>().Select(x => x.prodCode).ToList();
  618. }
  619. }
  620. temp.assists = await CommonFind.FindSchoolRoles(cosmosClient, temp.id, "assist");
  621. tempSchoolAssists.Add(temp);
  622. }
  623. yield return tempSchoolAssists;
  624. }
  625. /// <summary>
  626. /// 取得学校所有顾问列表
  627. /// </summary>
  628. /// <returns></returns>
  629. [ProducesDefaultResponseType]
  630. [HttpPost("get-schoolassist")]
  631. public async Task<IActionResult> GetSchoolAssist(JsonElement jsonElement)
  632. {
  633. try
  634. {
  635. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  636. string schoolId = (jsonElement.TryGetProperty("schoolId", out JsonElement _schoolId)) ? _schoolId.GetString() : string.Empty;
  637. Dictionary<string, List<Dictionary<string, string>>> haveSchoolManger = new();
  638. string managerWhereOption = (!string.IsNullOrWhiteSpace(schoolId)) ? $" AND c.code = 'Teacher-{schoolId}'" : string.Empty;
  639. //查询学校的顾问
  640. 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}";
  641. var cosmosClient = _azureCosmos.GetCosmosClient();
  642. //if ($"{site}".Equals(BIConst.Global))
  643. // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  644. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: managerSql, requestOptions: new QueryRequestOptions() { }))
  645. {
  646. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  647. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  648. {
  649. string id = obj.GetProperty("id").GetString(); //管理员ID
  650. string name = obj.GetProperty("name").GetString(); //管理员姓名
  651. string tempSchoolId = obj.GetProperty("schoolId").GetString(); //学校ID
  652. Dictionary<string, string> managerDic = new();
  653. managerDic.Add("id", id);
  654. managerDic.Add("name", name);
  655. if (haveSchoolManger.ContainsKey(tempSchoolId))
  656. {
  657. haveSchoolManger[tempSchoolId].Add(managerDic);
  658. }
  659. else
  660. {
  661. List<Dictionary<string, string>> managerList = new List<Dictionary<string, string>>();
  662. managerList.Add(managerDic);
  663. haveSchoolManger.Add(tempSchoolId, managerList);
  664. }
  665. }
  666. }
  667. //管理模组学校
  668. List<string> baseModuleSchoos = new List<string>();
  669. string baseWhereOption = (!string.IsNullOrEmpty(schoolId)) ? $" and c.id='{schoolId}'" : string.Empty;
  670. 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") }))
  671. {
  672. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  673. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  674. {
  675. string tempSchoolId = obj.GetProperty("id").GetString(); //学校ID
  676. baseModuleSchoos.Add(tempSchoolId);
  677. }
  678. }
  679. //学校信息
  680. List<object> schools = new List<object>();
  681. string schoolWhereOption = (!string.IsNullOrEmpty(schoolId)) ? $" where c.id='{schoolId}'" : string.Empty;
  682. 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") }))
  683. {
  684. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  685. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  686. {
  687. dynamic schoolExpando = new ExpandoObject();
  688. schoolExpando.id = obj.GetProperty("id").GetString();
  689. schoolExpando.name = obj.GetProperty("name").GetString();
  690. //schoolExpando.period = obj.GetProperty("period");
  691. schoolExpando.schoolCode = obj.GetProperty("schoolCode").GetString();
  692. schoolExpando.region = obj.GetProperty("region").GetString();
  693. schoolExpando.province = obj.GetProperty("province").GetString();
  694. schoolExpando.city = obj.GetProperty("city").GetString();
  695. schoolExpando.picture = obj.GetProperty("picture").GetString();
  696. if (haveSchoolManger.ContainsKey(schoolExpando.id))
  697. {
  698. schoolExpando.hasMarger = true;
  699. schoolExpando.managers = haveSchoolManger[schoolExpando.id];
  700. }
  701. else
  702. {
  703. schoolExpando.hasMarger = false;
  704. schoolExpando.managers = new List<object>();
  705. }
  706. schoolExpando.hasBaseModule = (baseModuleSchoos.Contains(schoolExpando.id)) ? true : false;
  707. schools.Add(schoolExpando);
  708. }
  709. }
  710. return Ok(new { state = 200, schools });
  711. }
  712. catch (Exception ex)
  713. {
  714. await _dingDing.SendBotMsg($"BI,{_option.Location} /batchschool/get-schools \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. [AuthToken(Roles = "admin,rdc")]
  725. [HttpPost("upd-schoolassist")]
  726. public async Task<IActionResult> UpdSchoolAssist(JsonElement jsonElement)
  727. {
  728. try
  729. {
  730. if (!jsonElement.TryGetProperty("schoolId", out JsonElement _schoolId)) return BadRequest();
  731. if (!jsonElement.TryGetProperty("name", out JsonElement schoolName)) return BadRequest();
  732. if (!jsonElement.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
  733. if (!jsonElement.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
  734. //if (!jsonElement.TryGetProperty("period", out JsonElement period)) return BadRequest();
  735. if (!jsonElement.TryGetProperty("picture", out JsonElement picture)) return BadRequest();
  736. if (!jsonElement.TryGetProperty("size", out JsonElement size)) return BadRequest();
  737. if (!jsonElement.TryGetProperty("scale", out JsonElement scale)) return BadRequest();
  738. if (!jsonElement.TryGetProperty("assistId", out JsonElement _assistId)) return BadRequest();
  739. if (!jsonElement.TryGetProperty("type", out JsonElement _type)) return BadRequest();
  740. //jsonElement.TryGetProperty("site", out JsonElement site);//分开部署,就不需要,一站多用时,取消注释
  741. var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  742. List<string> assistId = _assistId.ToObject<List<string>>();
  743. //List<string> periodS = period.ToObject<List<string>>();
  744. Dictionary<string, List<Dictionary<string, string>>> haveSchoolManger = new();
  745. var cosmosClient = _azureCosmos.GetCosmosClient();
  746. var tableClient = _azureStorage.GetCloudTableClient();
  747. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  748. //if ($"{site}".Equals(BIConst.Global))
  749. //{
  750. // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  751. // tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
  752. // blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
  753. //}
  754. School tempShool = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{_schoolId}", new PartitionKey("Base"));
  755. if (tempShool != null)
  756. {
  757. List<Period> periods = new();
  758. string campusId = Guid.NewGuid().ToString();
  759. //periodS.ForEach(x =>
  760. //{
  761. // periods.Add(new Period { id = Guid.NewGuid().ToString(), name = x.ToString(), campusId = campusId });
  762. //});
  763. //tempShool.period = periods;
  764. tempShool.size = !string.IsNullOrEmpty($"{size}") ? int.Parse($"{size}") : tempShool.size;
  765. tempShool.scale = !string.IsNullOrEmpty($"{scale}") ? int.Parse($"{scale}") : tempShool.scale;
  766. tempShool.picture = $"{picture}";
  767. tempShool.type = int.Parse($"{_type}");
  768. tempShool.name = $"{schoolName}";
  769. tempShool.areaId = $"{areaId}";
  770. tempShool.standard = $"{standard}";
  771. //修改学校
  772. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(tempShool, tempShool.id, new PartitionKey("Base"));
  773. //修改学校教师关联的信息
  774. string sql = $"SELECT distinct value(c) FROM c join A1 in c.schools where A1.schoolId='{tempShool.id}'";
  775. List<Teacher> teachers = new();
  776. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
  777. {
  778. teachers.Add(item);
  779. }
  780. foreach (var item in teachers)
  781. {
  782. Teacher.TeacherSchool teacherSchool = item.schools.Find(x => x.schoolId.Equals(tempShool.id));
  783. if (teacherSchool != null)
  784. {
  785. teacherSchool.name = tempShool.name;
  786. teacherSchool.picture = tempShool.picture;
  787. teacherSchool.areaId = tempShool.areaId;
  788. }
  789. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(item, item.id, new PartitionKey($"Base"));
  790. }
  791. if (assistId.Count > 0)
  792. {
  793. //修改学校顾问
  794. string sqlTxt = $"SELECT value(c) From c WHERE ARRAY_CONTAINS(c.roles,'assist',true)";
  795. List<SchoolTeacher> schoolTeachers = new();
  796. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<SchoolTeacher>(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{tempShool.id}") }))
  797. {
  798. if (!assistId.Contains(item.id))
  799. {
  800. if (item.roles.Contains("assist"))
  801. {
  802. item.roles.Remove("assist");
  803. if (item.roles.Count > 0)
  804. {
  805. await cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<SchoolTeacher>(item, item.id, new PartitionKey(item.code));
  806. }
  807. else
  808. {
  809. await cosmosClient.GetContainer("TEAMModelOS", "School").DeleteItemAsync<SchoolTeacher>(item.id, new PartitionKey(item.code));
  810. }
  811. }
  812. }
  813. }
  814. foreach (var itemTeacher in assistId)
  815. {
  816. Teacher tempTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>($"{itemTeacher}", new PartitionKey("Base"));
  817. if (tempTeacher != null)
  818. {
  819. var haveTeacher = tempTeacher.schools.Find(x => x.schoolId.Equals($"{_schoolId}"));
  820. if (haveTeacher != null)
  821. {
  822. //查询该教师是否存在该校
  823. SchoolTeacher schoolTeacher = null;
  824. try
  825. {
  826. schoolTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<SchoolTeacher>($"{itemTeacher}", new PartitionKey($"Teacher-{tempShool.id}"));
  827. }
  828. catch
  829. {
  830. }
  831. if (schoolTeacher != null)
  832. {
  833. if (!schoolTeacher.roles.Contains("assist"))
  834. {
  835. schoolTeacher.roles.Add("assist");
  836. //添加顾问权限
  837. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<SchoolTeacher>(schoolTeacher, schoolTeacher.id, new PartitionKey($"Teacher-{tempShool.id}"));
  838. }
  839. }
  840. else
  841. {
  842. SchoolTeacher addSchoolTeacher = new()
  843. {
  844. id = itemTeacher,
  845. code = $"Teacher-{tempShool.id}",
  846. pk = "Teacher",
  847. status = "join",
  848. roles = new List<string>() { "assist" },
  849. name = tempTeacher.name,
  850. job = $"{tempShool.name}-顾问",
  851. size = 0,
  852. createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
  853. };
  854. //添加学校顾问
  855. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(addSchoolTeacher, new PartitionKey($"Teacher-{tempShool.id}"));
  856. }
  857. }
  858. else
  859. {
  860. Teacher.TeacherSchool teacherSchool = new()
  861. {
  862. schoolId = tempShool.id,
  863. name = tempShool.name,
  864. status = "join",
  865. time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
  866. picture = tempShool.picture,
  867. areaId = tempShool.areaId
  868. };
  869. tempTeacher.schools.Add(teacherSchool);
  870. //给醍摩豆顾问添加学校
  871. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(tempTeacher, tempTeacher.id, new PartitionKey($"Base"));
  872. //不存在则在原来的基础上添加顾问角色
  873. SchoolTeacher addSchoolTeacher = new()
  874. {
  875. id = itemTeacher,
  876. code = $"Teacher-{tempShool.id}",
  877. pk = "Teacher",
  878. status = "join",
  879. roles = new List<string>() { "assist" },
  880. name = tempTeacher.name,
  881. job = $"{tempShool.name}-顾问",
  882. size = 0,
  883. createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
  884. };
  885. //添加学校学校顾问
  886. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(addSchoolTeacher, new PartitionKey($"Teacher-{tempShool.id}"));
  887. }
  888. }
  889. }
  890. }
  891. }
  892. //保存操作记录
  893. await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "school-update", $"{_tmdName}【{_tmdId}】修改学校功能,修改的学校:{_schoolId},{_type},{picture},{size},{string.Join("|", assistId.ToArray())}", _dingDing, httpContext: HttpContext);
  894. return Ok(new { state = 200 });
  895. }
  896. catch (Exception ex)
  897. {
  898. await _dingDing.SendBotMsg($"BI, {_option.Location} /batchschool/upd-schoolassist \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  899. return BadRequest();
  900. }
  901. }
  902. /// <summary>
  903. /// 查询区域的学校
  904. /// </summary>
  905. /// <param name="jsonElement"></param>
  906. /// <returns></returns>
  907. [ProducesDefaultResponseType]
  908. [HttpPost("get-schooldist")]
  909. public async Task<IActionResult> GetSchoolDist(JsonElement jsonElement)
  910. {
  911. try
  912. {
  913. if (!jsonElement.TryGetProperty("dist", out JsonElement _dist)) return BadRequest();
  914. //jsonElement.TryGetProperty("site", out JsonElement site); //分开部署,就不需要,一站多用时,取消注释
  915. var cosmosClient = _azureCosmos.GetCosmosClient();
  916. //if ($"{site}".Equals(BIConst.Global))
  917. // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  918. string sqltxt = $"SELECT * FROM c where c.dist='{_dist}'";
  919. List<School> schools = new List<School>();
  920. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<School>(queryText: sqltxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  921. {
  922. schools.Add(item);
  923. }
  924. return Ok(new { state = 200, schools });
  925. }
  926. catch (Exception ex)
  927. {
  928. await _dingDing.SendBotMsg($"BI,{_option.Location} /batchschool/get-schooldist \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  929. return BadRequest();
  930. }
  931. }
  932. /// <summary>
  933. /// 分页学校和顾问信息
  934. /// </summary>
  935. /// <param name="jsonElement"></param>
  936. /// <returns></returns>
  937. [ProducesDefaultResponseType]
  938. [HttpPost("get-schools")]
  939. public async Task<IActionResult> GetSchools(JsonElement jsonElement)
  940. {
  941. //List<School> schools = new List<School>();
  942. List<AssistSchool> schoolAssists = new List<AssistSchool>();
  943. if (!jsonElement.TryGetProperty("endPosition", out JsonElement endPosition)) return BadRequest();
  944. if (!jsonElement.TryGetProperty("pageSize", out JsonElement pageSize)) return BadRequest();
  945. //jsonElement.TryGetProperty("site", out JsonElement site); //分开部署,就不需要,一站多用时,取消注释
  946. var cosmosClient = _azureCosmos.GetCosmosClient();
  947. //if ($"{site}".Equals(BIConst.Global))
  948. // cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  949. string sqltxt = $"SELECT * FROM c order by c.id offset {endPosition} limit {pageSize}";
  950. await foreach (var itemSchool in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<School>(queryText: sqltxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  951. {
  952. AssistSchool schoolAssist = new()
  953. {
  954. id = itemSchool.id,
  955. code = itemSchool.code,
  956. schoolCode = itemSchool.schoolCode,
  957. name = itemSchool.name,
  958. region = itemSchool.region,
  959. province = itemSchool.province,
  960. city = itemSchool.city,
  961. dist = itemSchool.dist,
  962. size = itemSchool.size,
  963. address = itemSchool.address,
  964. picture = itemSchool.picture,
  965. type = itemSchool.type,
  966. scale = itemSchool.scale,
  967. areaId = itemSchool.areaId,
  968. standard = itemSchool.standard
  969. };
  970. schoolAssist.assists = await CommonFind.FindSchoolRoles(cosmosClient, itemSchool.id, "assist");
  971. schoolAssists.Add(schoolAssist);
  972. }
  973. return Ok(new { state = 200, schoolAssists });
  974. }
  975. /// <summary>
  976. /// 创校前检查数据
  977. /// </summary>
  978. /// <param name="jsonElement"></param>
  979. /// <returns></returns>
  980. [ProducesDefaultResponseType]
  981. [HttpPost("get-checlkexist")]
  982. public async Task<IActionResult> GetCheckExist(JsonElement jsonElement)
  983. {
  984. if (!jsonElement.TryGetProperty("scNames", out JsonElement _scNames)) return BadRequest();
  985. if (!jsonElement.TryGetProperty("accounts", out JsonElement _accounts)) return BadRequest();
  986. if (!jsonElement.TryGetProperty("areaIds", out JsonElement _areaIds)) return BadRequest();
  987. jsonElement.TryGetProperty("schools", out JsonElement schools);
  988. var cosmosClient = _azureCosmos.GetCosmosClient();
  989. List<CreateSchoolInfo> cSchools = new();
  990. if (!string.IsNullOrEmpty($"{schools}"))
  991. cSchools = schools.ToObject<List<CreateSchoolInfo>>();
  992. List<string> scNames = _scNames.ToObject<List<string>>();
  993. List<string> accounts = _accounts.ToObject<List<string>>();
  994. List<string> areaIds = _areaIds.ToObject<List<string>>();
  995. List<string> existScNames = new(); //存在的学校
  996. List<string> noAccounts = new(); // 不存在的账户
  997. List<string> noAreaIds = new(); //不存在的学区
  998. List<string> synPro = new(); //已同步省平台
  999. List<CreateSchoolInfo> createScInfo = new(); //学校简码信息
  1000. if (scNames.Count > 0)
  1001. {
  1002. foreach (var item in scNames)
  1003. {
  1004. //查询学校名称是否全字段匹配
  1005. await foreach (var sc in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: $"select value(c.name) from c where c.name='{item}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  1006. {
  1007. existScNames.Add(item);
  1008. }
  1009. }
  1010. }
  1011. if (accounts.Count > 0)
  1012. {
  1013. var content = new StringContent(_accounts.ToString(), Encoding.UTF8, "application/json");
  1014. string json = await _coreAPIHttpService.GetUserInfos(content);
  1015. List<TmdUserinfo> tmdInfos = json.ToObject<List<TmdUserinfo>>();
  1016. accounts.ForEach(ac =>
  1017. {
  1018. TmdUserinfo noTmdInfo = null;
  1019. tmdInfos.ForEach(tmd =>
  1020. {
  1021. if (!string.IsNullOrEmpty(tmd.id))
  1022. if (tmd.id.Equals($"{ac}"))
  1023. noTmdInfo = tmd;
  1024. if (!string.IsNullOrEmpty(tmd.mobile))
  1025. if (tmd.mobile.Equals($"{ac}"))
  1026. noTmdInfo = tmd;
  1027. if (!string.IsNullOrEmpty(tmd.mail))
  1028. if (tmd.mail.Equals($"{ac}"))
  1029. noTmdInfo = tmd;
  1030. });
  1031. //noTmdInfo = tmdInfos.Find(f => f.id.Equals($"{ac}") || f.mail.Equals($"{ac}") || f.mobile.Equals($"{ac}"));
  1032. if (noTmdInfo == null)
  1033. noAccounts.Add(ac);
  1034. });
  1035. }
  1036. if (areaIds.Count > 0)
  1037. {
  1038. foreach (var item in areaIds)
  1039. {
  1040. //查询区是否存在
  1041. var respAreaId = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{item}", new PartitionKey("Base-Area"));
  1042. if (respAreaId.Status != 200)
  1043. {
  1044. noAreaIds.Add(item);
  1045. }
  1046. //查询去是否同步省平台
  1047. var responseSet = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{item}", new PartitionKey("AreaSetting"));
  1048. if (responseSet.Status == 200)
  1049. {
  1050. using var fileJson = await JsonDocument.ParseAsync(responseSet.ContentStream);
  1051. AreaSetting delSet = fileJson.ToObject<AreaSetting>();
  1052. if (!string.IsNullOrEmpty(delSet.accessConfig))
  1053. synPro.Add(item);
  1054. }
  1055. }
  1056. }
  1057. foreach (var item in cSchools)
  1058. {
  1059. CreateSchoolInfo createSchoolInfo = item;
  1060. //生成学校ID
  1061. bool tempStaus = true;
  1062. do
  1063. {
  1064. createSchoolInfo = await SchoolCode.GenerateSchoolCode(createSchoolInfo, _dingDing, _environment);
  1065. var schoolStatu = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{createSchoolInfo.id}", new PartitionKey($"Base"));
  1066. if (schoolStatu.Status != 200) tempStaus = false;
  1067. else createSchoolInfo.createCount = createSchoolInfo.createCount >= 3 ? createSchoolInfo.createCount = 3 : createSchoolInfo.createCount += 1;
  1068. } while (tempStaus);
  1069. createScInfo.Add(createSchoolInfo);
  1070. }
  1071. if (existScNames.Count > 0 || noAccounts.Count > 0 || noAreaIds.Count > 0 || synPro.Count > 0)
  1072. return Ok(new { state = RespondCode.Created, existScNames, noAccounts, noAreaIds, synPro, createScInfo });
  1073. else
  1074. return Ok(new { state = RespondCode.Ok , createScInfo });
  1075. }
  1076. /// <summary>
  1077. /// 添加多个学校添加多个管理员
  1078. /// </summary>
  1079. /// <param name="jsonElement"></param>
  1080. /// <returns></returns>
  1081. [HttpPost("set-batchmanage")]
  1082. public async Task<IActionResult> SetBatchManage(JsonElement jsonElement)
  1083. {
  1084. if (!jsonElement.TryGetProperty("scIds", out JsonElement _scIds)) return BadRequest();
  1085. if (!jsonElement.TryGetProperty("manages", out JsonElement _manages)) return BadRequest();
  1086. var cosmosClient = _azureCosmos.GetCosmosClient();
  1087. List<string> scIds= _scIds.ToObject<List<string>>();
  1088. List<string> manages = _manages.ToObject<List<string>>();
  1089. List<ExistScManage> existScManages = new();
  1090. if (scIds.Count > 0 && manages.Count > 0)
  1091. {
  1092. foreach (var scId in scIds)
  1093. {
  1094. foreach (var msId in manages)
  1095. {
  1096. //不存在则在原来的基础上添加顾问角色
  1097. Teacher tempTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>($"{msId}", new PartitionKey("Base"));
  1098. if (tempTeacher != null)
  1099. {
  1100. var response = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{msId}", new PartitionKey($"Teacher-{scId}"));
  1101. if (response.Status == 200)
  1102. {
  1103. using var tchJson = await JsonDocument.ParseAsync(response.ContentStream);
  1104. SchoolTeacher tchSc = tchJson.ToObject<SchoolTeacher>();
  1105. if (tchSc.roles.Contains("admin"))
  1106. {
  1107. tchSc.roles.Add("admin");
  1108. //添加顾问权限
  1109. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<SchoolTeacher>(tchSc, tchSc.id, new PartitionKey($"Teacher-{scId}"));
  1110. }
  1111. else
  1112. existScManages.Add(new ExistScManage() { scId = scId, tmdId = msId });
  1113. }
  1114. else
  1115. {
  1116. SchoolTeacher addSchoolTeacher = new()
  1117. {
  1118. id = tempTeacher.id,
  1119. code = $"Teacher-{scId}",
  1120. pk = "Teacher",
  1121. status = "join",
  1122. roles = new List<string>() { "admin" },
  1123. name = tempTeacher.name,
  1124. job = $"管理员",
  1125. size = 0,
  1126. createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
  1127. };
  1128. var haveTeacher = tempTeacher.schools.Find(x => x.schoolId.Equals($"{scId}"));
  1129. if (haveTeacher == null)
  1130. {
  1131. School school = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemAsync<School>(scId, new PartitionKey("Base"));
  1132. //教师存在,在该教师信息中添加要管理的学校信息
  1133. tempTeacher.schools.Add(new Teacher.TeacherSchool { areaId = string.IsNullOrEmpty(school.areaId) ? "" : school.areaId, schoolId = school.id, name = school.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() });
  1134. tempTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(tempTeacher, msId, new PartitionKey("Base"));
  1135. }
  1136. //添加学校学校顾问
  1137. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(addSchoolTeacher, new PartitionKey($"Teacher-{scId}"));
  1138. }
  1139. }
  1140. else
  1141. {
  1142. CoreUser coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", $"{msId}" } }, _option.Location, _configuration);
  1143. Teacher teacher = new() { id = coreUser.id, name = coreUser.name, picture = coreUser.picture, pk = "Base", code = "Base", size = 1, createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() };
  1144. var responseSc = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(scId, new PartitionKey("Base"));
  1145. if (responseSc.Status == 200)
  1146. {
  1147. using var tchJson = await JsonDocument.ParseAsync(responseSc.ContentStream);
  1148. School scInfo = tchJson.ToObject<School>();
  1149. teacher.schools.Add(new() { schoolId = scInfo.id, name = scInfo.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), picture = scInfo.picture, areaId = scInfo.areaId });
  1150. }
  1151. teacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey("Base"));
  1152. SchoolTeacher addSchoolTeacher = new()
  1153. {
  1154. id = coreUser.id,
  1155. code = $"Teacher-{scId}",
  1156. pk = "Teacher",
  1157. status = "join",
  1158. roles = new List<string>() { "admin" },
  1159. name = coreUser.name,
  1160. job = $"管理员",
  1161. size = 0,
  1162. createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
  1163. };
  1164. //添加学校学校顾问
  1165. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(addSchoolTeacher, new PartitionKey($"Teacher-{scId}"));
  1166. }
  1167. }
  1168. }
  1169. }
  1170. if (existScManages.Count > 0)
  1171. return Ok(new { state = RespondCode.Created, existScManages });
  1172. else
  1173. return Ok(new { state = RespondCode.Ok });
  1174. }
  1175. #region 预设学校基础信息 多语言
  1176. /// <summary>
  1177. /// 预设学校基础信息 多语言
  1178. /// </summary>
  1179. /// <param name="period"></param>
  1180. /// <param name="Language"></param>
  1181. /// <param name="campusId"></param>
  1182. /// <returns></returns>
  1183. public List<Period> PresetSchoolPeriod(List<string> period, string Language, string campusId)
  1184. {
  1185. var builder = $"{_environment.ContentRootPath}/JsonFile/Preset/LangSchoolConfig.json";
  1186. StreamReader streamReader = new(new FileStream(builder, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8);
  1187. StringBuilder stringBuilder = new();
  1188. string text;
  1189. while ((text = streamReader.ReadLine()) != null)
  1190. {
  1191. stringBuilder.Append(text.ToString());
  1192. }
  1193. streamReader.Close();
  1194. string input = stringBuilder.ToString();
  1195. List<SchoolConfig> schoolConfigs = input.ToObject<List<SchoolConfig>>();
  1196. SchoolConfig schoolConfig = schoolConfigs.Find(x => x.Lang.Contains($"{Language}"));
  1197. if (schoolConfig == null)
  1198. {
  1199. if (Language.Contains("en"))
  1200. schoolConfig = schoolConfigs.Find(x => x.Lang.Contains("en-US"));
  1201. else
  1202. schoolConfig = schoolConfigs.Find(x => x.Lang.Contains("zh-CN"));
  1203. }
  1204. List<Period> periods = new();
  1205. period.ForEach(x =>
  1206. {
  1207. periods.Add(new Period
  1208. {
  1209. id = Guid.NewGuid().ToString(),
  1210. name = x,
  1211. campusId = campusId,
  1212. 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() },
  1213. 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() } },
  1214. subjects = new List<Subject>() {
  1215. new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[0].name,type=schoolConfig.PresetSubject[0].type },
  1216. new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[1].name,type=schoolConfig.PresetSubject[1].type },
  1217. new Subject { id=Guid.NewGuid().ToString(),name=schoolConfig.PresetSubject[2].name,type=schoolConfig.PresetSubject[2].type }
  1218. },
  1219. grades = schoolConfig.grades,
  1220. analysis = new Analysis()
  1221. {
  1222. type = new List<ExamSimple>() { new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[0].name },
  1223. new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[1].name },
  1224. new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[2].name },
  1225. new ExamSimple { id = Guid.NewGuid().ToString(), name = schoolConfig.PresetExam[0].type[3].name } },
  1226. income = schoolConfig.PresetExam[0].income,
  1227. eugenics = schoolConfig.PresetExam[0].eugenics,
  1228. touch = schoolConfig.PresetExam[0].touch
  1229. }
  1230. });
  1231. });
  1232. return periods;
  1233. }
  1234. public record SchoolConfig
  1235. {
  1236. public string Lang { get; set; }
  1237. public List<semester> semester { get; set; }
  1238. public List<string> grades { get; set; }
  1239. public List<PresetSubject> PresetSubject { get; set; }
  1240. public List<PresetExam> PresetExam { get; set; }
  1241. }
  1242. public record semester
  1243. {
  1244. public string id { get; set; } = Guid.NewGuid().ToString();
  1245. public string term { get; set; }
  1246. public int start { get; set; }
  1247. public int month { get; set; }
  1248. public int day { get; set; }
  1249. }
  1250. public record PresetSubject
  1251. {
  1252. public string id { get; set; } = Guid.NewGuid().ToString();
  1253. public string name { get; set; }
  1254. public int type { get; set; }
  1255. }
  1256. public record PresetExam
  1257. {
  1258. public List<StudyType> type { get; set; }
  1259. public int income { get; set; }
  1260. public int eugenics { get; set; }
  1261. public int touch { get; set; }
  1262. }
  1263. public record StudyType
  1264. {
  1265. public string id { get; set; } = Guid.NewGuid().ToString();
  1266. public string name { get; set; }
  1267. }
  1268. #endregion
  1269. //public class SchoolAssist
  1270. //{
  1271. // public string id { get; set; }
  1272. // public string code { get; set; }
  1273. // public string schoolCode { get; set; }
  1274. // public string name { get; set; }
  1275. // public string region { get; set; }
  1276. // public string province { get; set; }
  1277. // public string city { get; set; }
  1278. // public string dist { get; set; }
  1279. // public int size { get; set; }
  1280. // public string address { get; set; }
  1281. // public string picture { get; set; }
  1282. // public int type { get; set; }
  1283. // public int scale { get; set; }
  1284. // public string standard { get; set; }
  1285. // public string areaId { get; set; }
  1286. // public List<SchoolTeacherRoles> assists { get; set; }
  1287. // public int serial { get; set; } //软体
  1288. // public int service { get; set; } //服务
  1289. // public int hard { get; set; } //硬体
  1290. // //public List<SchoolProductSumData> serial { get; set; } //软体
  1291. // //public List<SchoolProductSumData> service { get; set; } //服务
  1292. // //public List<SchoolProductSumDataHard> hard { get; set; } //硬体
  1293. //}
  1294. /// <summary>
  1295. /// 创建多个学校实体
  1296. /// </summary>
  1297. public record FoundSchools()
  1298. {
  1299. /// <summary>
  1300. /// 语系
  1301. /// </summary>
  1302. public string lang { get; set; }
  1303. /// <summary>
  1304. /// 站点
  1305. /// </summary>
  1306. public string site { get; set; }
  1307. /// <summary>
  1308. /// 批量创校的数据结构
  1309. /// </summary>
  1310. public List<BISchool> biSchools { get; set; } = new List<BISchool>();
  1311. }
  1312. /// <summary>
  1313. /// 批量创校的数据结构
  1314. /// </summary>
  1315. public record BISchool()
  1316. {
  1317. /// <summary>
  1318. /// 学校名称
  1319. /// </summary>
  1320. public string name { get; set; }
  1321. /// <summary>
  1322. /// 学校管理员
  1323. /// </summary>
  1324. public List<string> admin { get; set; }
  1325. /// <summary>
  1326. /// 学校的学段
  1327. /// </summary>
  1328. public List<string> period { get; set; }
  1329. /// <summary>
  1330. /// 学校空间大小
  1331. /// </summary>
  1332. public int size { get; set; }
  1333. /// <summary>
  1334. /// 地区
  1335. /// </summary>
  1336. public string region { get; set; }
  1337. /// <summary>
  1338. /// 省份
  1339. /// </summary>
  1340. public string province { get; set; }
  1341. /// <summary>
  1342. /// 城市
  1343. /// </summary>
  1344. public string city { get; set; }
  1345. /// <summary>
  1346. /// 县,区,郡
  1347. /// </summary>
  1348. public string dist { get; set; }
  1349. /// <summary>
  1350. /// 学校详细地址
  1351. /// </summary>
  1352. public string address { get; set; }
  1353. /// <summary>
  1354. /// 学校类型
  1355. /// </summary>
  1356. public int type { get; set; }
  1357. /// <summary>
  1358. /// 区域ID
  1359. /// </summary>
  1360. public string areaId { get; set; }
  1361. /// <summary>
  1362. /// 区域标准
  1363. /// </summary>
  1364. public string standard { get; set; }
  1365. }
  1366. public record ExistScManage
  1367. {
  1368. public string scId{ get; set; }
  1369. public string tmdId { get; set; }
  1370. }
  1371. }
  1372. }