BatchSchoolController.cs 108 KB

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