BatchSchoolController.cs 112 KB

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