SchoolController.cs 115 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094
  1. using Azure.Cosmos;
  2. using HTEXLib.COMM.Helpers;
  3. using MathNet.Numerics.LinearAlgebra;
  4. using MathNet.Numerics.LinearAlgebra.Double;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.AspNetCore.Mvc;
  7. using Microsoft.Extensions.Configuration;
  8. using Microsoft.Extensions.Options;
  9. using StackExchange.Redis;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Net.Http;
  14. using System.Text;
  15. using System.Text.Json;
  16. using System.Threading.Tasks;
  17. using TEAMModelBI.DI.BIAzureStorage;
  18. using TEAMModelBI.Filter;
  19. using TEAMModelBI.Models;
  20. using TEAMModelBI.Tool;
  21. using TEAMModelBI.Tool.CosmosBank;
  22. using TEAMModelBI.Tool.Extension;
  23. using TEAMModelOS.Models;
  24. using TEAMModelOS.SDK;
  25. using TEAMModelOS.SDK.Context.BI;
  26. using TEAMModelOS.SDK.Context.Constant;
  27. using TEAMModelOS.SDK.DI;
  28. using TEAMModelOS.SDK.Extension;
  29. using TEAMModelOS.SDK.Models;
  30. using TEAMModelOS.SDK.Models.Cosmos.BI;
  31. using TEAMModelOS.SDK.Models.Cosmos.Common;
  32. using TEAMModelOS.SDK.Models.Service;
  33. using TEAMModelOS.SDK.Models.Service.BI;
  34. namespace TEAMModelBI.Controllers.BISchool
  35. {
  36. [Route("schoolcheck")]
  37. [ApiController]
  38. public class SchoolController : ControllerBase
  39. {
  40. private readonly AzureCosmosFactory _azureCosmos;
  41. private readonly DingDing _dingDing;
  42. private readonly Option _option;
  43. private readonly AzureStorageFactory _azureStorage;
  44. private readonly AzureRedisFactory _azureRedis;
  45. private readonly IConfiguration _configuration;
  46. private readonly NotificationService _notificationService;
  47. private readonly CoreAPIHttpService _coreAPIHttpService;
  48. public SchoolController(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, AzureRedisFactory azureRedis, IConfiguration configuration, NotificationService notificationService, CoreAPIHttpService coreAPIHttpService)
  49. {
  50. _azureCosmos = azureCosmos;
  51. _dingDing = dingDing;
  52. _azureStorage = azureStorage;
  53. _option = option?.Value;
  54. _azureRedis = azureRedis;
  55. _configuration = configuration;
  56. _notificationService = notificationService;
  57. _coreAPIHttpService = coreAPIHttpService;
  58. }
  59. /// <summary>
  60. /// 查询未加入区域的学校
  61. /// </summary>
  62. /// <returns></returns>
  63. [ProducesDefaultResponseType]
  64. [HttpPost("get-notarea")]
  65. public async Task<IActionResult> GetNotAreaSchool(JsonElement jsonElement)
  66. {
  67. try
  68. {
  69. jsonElement.TryGetProperty("areaId", out JsonElement areaId);
  70. jsonElement.TryGetProperty("site", out JsonElement site);
  71. var cosmosClient = _azureCosmos.GetCosmosClient();
  72. if ($"{site}".Equals(BIConst.Global))
  73. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  74. //默认不指定返回大小
  75. int? pageSize = null;
  76. string continuationToken = string.Empty;
  77. string pageToken = default;
  78. if (jsonElement.TryGetProperty("pageSize", out JsonElement jsonPageSize))
  79. {
  80. if (!jsonPageSize.ValueKind.Equals(JsonValueKind.Undefined) && !jsonPageSize.ValueKind.Equals(JsonValueKind.Null) && jsonPageSize.TryGetInt32(out int tempPageSize))
  81. {
  82. pageSize = tempPageSize;
  83. }
  84. }
  85. //是否需要进行分页查询,默认不分页
  86. bool iscontinuation = false;
  87. if (pageSize != null && pageSize.Value > 0)
  88. {
  89. iscontinuation = true;
  90. }
  91. if (jsonElement.TryGetProperty("contToken", out JsonElement ContToken))
  92. {
  93. pageToken = ContToken.GetString();
  94. }
  95. StringBuilder sqltxt = new($"SELECT c.id,c.name,c.schoolCode,c.province,c.city,c.dist,c.picture,c.period,c.areaId,c.standard,c.manyAreas FROM c");
  96. if (!string.IsNullOrEmpty($"{areaId}"))
  97. {
  98. sqltxt.Append($" WHERE c.areaId !='{areaId}'");
  99. }
  100. else
  101. {
  102. sqltxt.Append($" WHERE c.areaId ='' and c.standard = ''");
  103. }
  104. List<NotAreaSchool> tempNotAreaSchools = new();
  105. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: sqltxt.ToString(), continuationToken: pageToken, requestOptions: new QueryRequestOptions() { MaxItemCount = pageSize, PartitionKey = new PartitionKey("Base") }))
  106. {
  107. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  108. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  109. {
  110. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  111. {
  112. //List<string> temp0 = obj.GetProperty("period").ToObject<List<Period>>().Select(x=>x.name).ToList();
  113. NotAreaSchool notAreaSchool = new NotAreaSchool()
  114. {
  115. id = obj.GetProperty("id").GetString(),
  116. name = obj.GetProperty("name").GetString(),
  117. schoolCode = obj.GetProperty("schoolCode").GetString(),
  118. picture = obj.GetProperty("picture").GetString(),
  119. period = obj.GetProperty("period").ToObject<List<Period>>().Select(x => x.name).ToList(),
  120. province = obj.GetProperty("province").GetString(),
  121. city = obj.GetProperty("city").GetString(),
  122. dist = obj.GetProperty("dist").GetString(),
  123. areaId = obj.GetProperty("areaId").GetString(),
  124. standard = obj.GetProperty("standard").GetString()
  125. };
  126. try
  127. {
  128. notAreaSchool.areas = obj.GetProperty("manyAreas").ToObject<List<SchoolArea>>();
  129. }
  130. catch { }
  131. tempNotAreaSchools.Add(notAreaSchool);
  132. }
  133. if (iscontinuation)
  134. {
  135. continuationToken = item.GetContinuationToken();
  136. break;
  137. }
  138. }
  139. }
  140. List<NotAreaSchool> notAreaSchools = new List<NotAreaSchool>();
  141. tempNotAreaSchools.ForEach(nas =>
  142. {
  143. if (nas.areas == null)
  144. notAreaSchools.Add(nas);
  145. else
  146. {
  147. var not = nas.areas.Find(f => f.areaId == $"{areaId}");
  148. if (not == null)
  149. notAreaSchools.Add(nas);
  150. }
  151. });
  152. //if (!string.IsNullOrEmpty($"{areaId}"))
  153. // notAreaSchools = notAreaSchools.Select(na => new NotAreaSchool { id = na.id, name = na.name, schoolCode = na.schoolCode, picture = na.picture, period = na.period, province = na.province, city = na.city = na.city, dist = na.dist, manyAreas = new List<ManyArea> { na.manyAreas.Find(m => m.areaId != $"{areaId}") } }).ToList();
  154. return Ok(new { state = 200, continuationToken, pageSize, notAreaSchools });
  155. }
  156. catch (Exception ex)
  157. {
  158. await _dingDing.SendBotMsg($"BI,{_option.Location} /schoolcheck/get-notarea \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  159. return BadRequest();
  160. }
  161. }
  162. /// <summary>
  163. /// 学校加入区
  164. /// </summary>
  165. /// <param name="jsonElement"></param>
  166. /// <returns></returns>
  167. [ProducesDefaultResponseType]
  168. [AuthToken(Roles = "admin,rdc,assist,sales")]
  169. [HttpPost("set-schooljoinarea")]
  170. public async Task<IActionResult> SetSchoolJoinArea(JsonElement jsonElement)
  171. {
  172. try
  173. {
  174. if (!jsonElement.TryGetProperty("standard", out JsonElement standard)) return BadRequest();
  175. if (!jsonElement.TryGetProperty("schoolCode", out JsonElement _schoolCode)) return BadRequest();
  176. if (!jsonElement.TryGetProperty("areaId", out JsonElement _areaId)) return BadRequest();
  177. jsonElement.TryGetProperty("areaName", out JsonElement areaName);
  178. jsonElement.TryGetProperty("isDefault", out JsonElement isDefault);
  179. jsonElement.TryGetProperty("site", out JsonElement site);
  180. var isManyArea = false;
  181. if (!string.IsNullOrEmpty($"{isDefault}"))
  182. {
  183. isManyArea = true;
  184. }
  185. var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  186. List<string> schoolCodes = _schoolCode.ToObject<List<string>>();
  187. StringBuilder msg = new($"{_tmdName}【{_tmdId}】操作学校加入区域功能,加入的区域:{standard},学校ID:{string.Join("|", schoolCodes.ToArray())}");
  188. var cosmosClient = _azureCosmos.GetCosmosClient();
  189. var tableClient = _azureStorage.GetCloudTableClient();
  190. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  191. if ($"{site}".Equals(BIConst.Global))
  192. {
  193. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  194. tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
  195. blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
  196. }
  197. var responseSet = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemStreamAsync($"{_areaId}", new PartitionKey("AreaSetting"));
  198. if (responseSet.Status == 200)
  199. {
  200. using var fileJson = await JsonDocument.ParseAsync(responseSet.ContentStream);
  201. AreaSetting delSet = fileJson.ToObject<AreaSetting>();
  202. if (!string.IsNullOrEmpty(delSet.accessConfig))
  203. return Ok(new { state = 401, msg = "区域已经规定了,不能切换能能力" });
  204. }
  205. if (schoolCodes.Count > 0)
  206. {
  207. foreach (var tempCode in schoolCodes)
  208. {
  209. School school = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(tempCode, new PartitionKey("Base"));
  210. if (school != null)
  211. {
  212. if (isManyArea)
  213. {
  214. if (school.areas == null)
  215. school.areas = new List<SchoolArea>() { new SchoolArea() { areaId = $"{_areaId}", name = $"{areaName}", status = "join" } };
  216. else
  217. {
  218. var marea = school.areas.Find(ma => ma.areaId == $"{_areaId}");
  219. if (marea == null)
  220. school.areas.Add(new SchoolArea() { areaId = $"{_areaId}", name = $"{areaName}", status = $"join" });
  221. }
  222. }
  223. school.standard = $"{standard}";
  224. school.areaId = $"{_areaId}";
  225. msg.Append($"{school.name}【{school.id}】学校移除多区域的名单:");
  226. List<Teacher> teachers = new();
  227. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<Teacher>(queryText: $"SELECT value(c) FROM c join s in c.schools where s.schoolId ='{school.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  228. {
  229. teachers.Add(item);
  230. }
  231. foreach (var item in teachers)
  232. {
  233. msg.Append($"{item.name}[{item.id}]");
  234. var tchSchool = item.schools.Find(f => f.schoolId.Equals($"{school.id}") && f.areaId.Equals($"{_areaId}"));
  235. if (tchSchool == null)
  236. {
  237. Teacher.TeacherSchool teacherSchool = new() { schoolId = school.id, name = school.name, status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), picture = school.picture, areaId = school.areaId };
  238. item.schools.Add(teacherSchool);
  239. await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(item, item.id, new PartitionKey("Base"));
  240. }
  241. }
  242. await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(school, school.id, new PartitionKey(school.code));
  243. }
  244. }
  245. }
  246. //保存操作记录
  247. //await _azureStorage.SaveBILog("school-update", $"{_tmdName}【{_tmdId}】操作学校加入区域功能,加入的区域:{standard},学校ID:{string.Join("|", schoolCodes.ToArray())}", _dingDing, httpContext: HttpContext);
  248. await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "school-update", msg.ToString(), _dingDing, httpContext: HttpContext);
  249. return Ok(new { state = 200 });
  250. }
  251. catch (Exception ex)
  252. {
  253. await _dingDing.SendBotMsg($"BI,{_option.Location} /schoolcheck/set-schooljoinarea \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  254. return BadRequest();
  255. }
  256. }
  257. /// <summary>
  258. /// 依据醍摩豆账户查询顾问管理学校的基础信息
  259. /// </summary>
  260. /// <param name="jsonElement"></param>
  261. /// <returns></returns>
  262. [HttpPost("get-assistschool")]
  263. public async Task<IActionResult> GetAssistSchool(JsonElement jsonElement)
  264. {
  265. try
  266. {
  267. if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
  268. jsonElement.TryGetProperty("site", out JsonElement site);
  269. List<object> schools = new List<object>();
  270. var cosmosClient = _azureCosmos.GetCosmosClient();
  271. if ($"{site}".Equals(BIConst.Global))
  272. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  273. //List<string> schoolIds = new List<string>();
  274. //string sqlTxt = $"SELECT DISTINCT REPLACE(c.code, 'Teacher-', '') AS schoolId FROM c WHERE c.pk = 'Teacher' AND c.status = 'join' AND ARRAY_CONTAINS(c.roles, 'assist', true) AND c.id='{tmdId}' ";
  275. //await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { }))
  276. //{
  277. // using var json = await JsonDocument.ParseAsync(item.ContentStream);
  278. // foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  279. // {
  280. // schoolIds.Add(obj.GetProperty("schoolId").GetString());
  281. // }
  282. //}
  283. List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
  284. foreach (var item in schoolIds)
  285. {
  286. await foreach (var itemBase in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"select c.id,c.code,c.name,c.picture,c.region,c.province,c.city,c.dist from c where c.id='{item}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  287. {
  288. var json = await JsonDocument.ParseAsync(itemBase.ContentStream);
  289. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  290. {
  291. schools.Add(obj.ToObject<object>());
  292. }
  293. }
  294. }
  295. return Ok(new { state = 200, schools });
  296. }
  297. catch (Exception ex)
  298. {
  299. await _dingDing.SendBotMsg($"BI,{_option.Location} /schoolcheck/get-assustschool \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  300. return BadRequest();
  301. }
  302. }
  303. /// <summary>
  304. /// 依据学校编号查询学校信息
  305. /// </summary>
  306. /// <param name="jsonElement"></param>
  307. /// <returns></returns>
  308. [HttpPost("get-schoolid")]
  309. public async Task<IActionResult> GetSchoolId(JsonElement jsonElement)
  310. {
  311. try
  312. {
  313. if (!jsonElement.TryGetProperty("schoolId", out JsonElement schoolId)) return BadRequest();
  314. jsonElement.TryGetProperty("site", out JsonElement site);
  315. var cosmosClient = _azureCosmos.GetCosmosClient();
  316. if ($"{site}".Equals(BIConst.Global))
  317. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  318. AssistSchool schoolAssists = new(); //返回学校列表集合
  319. string sqlTxt = $"select c.id,c.code,c.schoolCode,c.name,c.region,c.province,c.city,c.dist,c.size,c.address,c.picture,c.type,c.scale,c.areaId,c.standard,c.period from c where c.id='{schoolId}'";
  320. await foreach (var itemSchool in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<AssistSchool>(queryText: sqlTxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  321. {
  322. //schoolAssists.Add(itemSchool);
  323. schoolAssists = itemSchool;
  324. //school = itemSchool;
  325. }
  326. if (schoolAssists.id != null)
  327. {
  328. var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(schoolAssists.id, new PartitionKey("ProductSum"));
  329. if (response.Status == 200)
  330. {
  331. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  332. if (json.RootElement.TryGetProperty("serial", out JsonElement serial) && !serial.ValueKind.Equals(JsonValueKind.Null))
  333. {
  334. schoolAssists.serial = serial.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
  335. }
  336. if (json.RootElement.TryGetProperty("service", out JsonElement service) && !service.ValueKind.Equals(JsonValueKind.Null))
  337. {
  338. schoolAssists.service = service.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
  339. }
  340. if (json.RootElement.TryGetProperty("hard", out JsonElement hard) && !hard.ValueKind.Equals(JsonValueKind.Null))
  341. {
  342. schoolAssists.hard = hard.ToObject<List<SchoolProductSumDataHard>>().Select(x => x.prodCode).ToList();
  343. }
  344. }
  345. schoolAssists.assists = await CommonFind.FindSchoolRoles(cosmosClient, schoolAssists.id, "assist");
  346. schoolAssists.lessonCount = await CommonFind.FindTotals(cosmosClient, $"select count(c.id) as totals from c ", "School", $"LessonRecord-{schoolAssists.id}");
  347. return Ok(new { state = 200, schoolAssists });
  348. }
  349. else return Ok(new { state = 404, msg = "未找到该学校!" });
  350. }
  351. catch (Exception ex)
  352. {
  353. await _dingDing.SendBotMsg($"BI,{_option.Location} /schoolcheck/get-schoolid \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  354. return BadRequest();
  355. }
  356. }
  357. /// <summary>
  358. /// 修改学校信息
  359. /// </summary>
  360. /// <param name="school"></param>
  361. /// <returns></returns>
  362. [ProducesDefaultResponseType]
  363. [AuthToken(Roles = "admin,rdc,assist,sales")]
  364. [HttpPost("upd-school")]
  365. public async Task<IActionResult> UpdSchool(School school, [FromHeader] string site)
  366. {
  367. try
  368. {
  369. School schoolInfo = new School();
  370. var cosmosClient = _azureCosmos.GetCosmosClient();
  371. var tableClient = _azureStorage.GetCloudTableClient();
  372. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  373. if ($"{site}".Equals(BIConst.Global))
  374. {
  375. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  376. tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
  377. blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
  378. }
  379. string _auth = HttpContext.GetXAuth("AuthToken");
  380. //var (tmdId, tmdName) = HttpJwtAnalysis.JwtXAuth(_auth, _option);
  381. var (tmdId, tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(_auth, _option);
  382. var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(school.id, new PartitionKey($"Base"));
  383. if (response.Status == 200)
  384. {
  385. string sql = $"SELECT distinct value(c) FROM c join A1 in c.schools where A1.schoolId='{school.id}'";
  386. List<Teacher> teachers = new List<Teacher>();
  387. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<Teacher>(sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
  388. {
  389. teachers.Add(item);
  390. }
  391. foreach (var item in teachers)
  392. {
  393. Teacher.TeacherSchool teacherSchool = item.schools.Find(x => x.schoolId.Equals(school.id));
  394. if (teacherSchool != null)
  395. {
  396. teacherSchool.name = school.name;
  397. teacherSchool.picture = school.picture;
  398. teacherSchool.areaId = school.areaId;
  399. }
  400. await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync(item, item.id, new PartitionKey($"Base"));
  401. }
  402. schoolInfo = await cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<School>(school, school.id, new PartitionKey($"Base"));
  403. //保存操作记录
  404. //await _azureStorage.SaveBILog("school-update", $"{tmdName}【{tmdId}】修改学校信息,学校和ID:{school.name}【{school.id}】", _dingDing, httpContext: HttpContext);
  405. await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "school-update", $"{tmdName}【{tmdId}】修改学校信息,学校和ID:{school.name}【{school.id}】", _dingDing, httpContext: HttpContext);
  406. }
  407. else return Ok(new { state = 400, message = "请求错误!" });
  408. return Ok(new { state = 200, schoolInfo });
  409. //School tempShool = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(replaceSchool.school.id, new PartitionKey("Base"));
  410. //if (tempShool != null)
  411. //{
  412. // List<Teacher> teachers = new List<Teacher>();
  413. // string sqltxt = $"select distinct value(c) from c join a1 in c.schools where a1.schoolId='{replaceSchool.school.id}'";
  414. // await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(queryText: sqltxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  415. // {
  416. // teachers.Add(item);
  417. // }
  418. // foreach (var item in teachers)
  419. // {
  420. // Teacher.TeacherSchool teacherSchool = item.schools.Find(x => x.schoolId.Equals(replaceSchool.school.id));
  421. // if (teacherSchool != null)
  422. // {
  423. // teacherSchool.name = replaceSchool.school.name;
  424. // teacherSchool.picture = replaceSchool.school.picture;
  425. // teacherSchool.areaId = replaceSchool.school.areaId;
  426. // }
  427. // await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(item, item.id, new PartitionKey("Base"));
  428. // }
  429. // schoolInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<School>(replaceSchool.school, replaceSchool.school.id, new PartitionKey("Base"));
  430. // //保存操作记录
  431. // await _azureStorage.SaveBILog("school-update", $"{replaceSchool.tmdName}【{replaceSchool.tmdId}】修改学校信息,学校和ID:{replaceSchool.school.name}【{replaceSchool.school.id}】", _dingDing, httpContext: HttpContext);
  432. // return Ok(new { state = 200, schoolInfo });
  433. //}
  434. //else return Ok(new { state = 400, message = "请求错误!" });
  435. }
  436. catch (Exception ex)
  437. {
  438. await _dingDing.SendBotMsg($"BI,{_option.Location} /batchschool/upd-school \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  439. return BadRequest();
  440. }
  441. }
  442. /// <summary>
  443. /// 顾问学校空间使用情况
  444. /// </summary>
  445. /// <param name="jsonElement"></param>
  446. /// <returns></returns>
  447. [HttpPost("get-assistspace")]
  448. public async Task<IActionResult> GetAssistSchoolSpace(JsonElement jsonElement)
  449. {
  450. if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
  451. jsonElement.TryGetProperty("site", out JsonElement site);
  452. var cosmosClient = _azureCosmos.GetCosmosClient();
  453. if ($"{site}".Equals(BIConst.Global))
  454. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  455. List<string> schools = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
  456. List<SchoolSpace> schoolSpaces = new();
  457. foreach (var sid in schools)
  458. {
  459. School school = new();
  460. var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(sid, new PartitionKey("Base"));
  461. if (response.Status == 200)
  462. {
  463. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  464. school = json.ToObject<School>();
  465. }
  466. long teach = 0;
  467. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"SELECT sum(c.size) as size FROM c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{sid}") }))
  468. {
  469. var json = await JsonDocument.ParseAsync(item.ContentStream);
  470. foreach (var elmt in json.RootElement.GetProperty("Documents").EnumerateArray())
  471. {
  472. if (elmt.TryGetProperty("size", out JsonElement _size) && _size.ValueKind.Equals(JsonValueKind.Number))
  473. {
  474. teach = _size.GetInt32();
  475. break;
  476. }
  477. }
  478. }
  479. SchoolSpace schoolSpace = new() { id = sid, name = school != null ? school.name : sid };
  480. Space space = new Space();
  481. long blobsize = 0; //使用大小
  482. RedisValue value = default;
  483. value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", sid);
  484. if (value != default && !value.IsNullOrEmpty)
  485. {
  486. JsonElement record = value.ToString().ToObject<JsonElement>();
  487. if (record.TryGetInt64(out blobsize))
  488. {
  489. }
  490. }
  491. else
  492. {
  493. var client = _azureStorage.GetBlobContainerClient(sid);
  494. var size = await client.GetBlobsCatalogSize();
  495. await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", sid, size.Item1);
  496. foreach (var key in size.Item2.Keys)
  497. {
  498. await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{sid}", key);
  499. await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{sid}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
  500. }
  501. space.useSize = (long)size.Item1; space.tSize = teach; space.catalogSize = size.Item2;
  502. schoolSpace.space = space;
  503. schoolSpaces.Add(schoolSpace);
  504. continue;
  505. }
  506. Dictionary<string, double?> catalog = new Dictionary<string, double?>();
  507. SortedSetEntry[] Scores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Blob:Catalog:{sid}");
  508. if (Scores != null)
  509. {
  510. foreach (var score in Scores)
  511. {
  512. double val = score.Score;
  513. string key = score.Element.ToString();
  514. catalog.Add(key, val);
  515. }
  516. space.useSize = blobsize; space.tSize = teach; space.catalogSize = catalog;
  517. schoolSpace.space = space;
  518. schoolSpaces.Add(schoolSpace);
  519. continue;
  520. }
  521. else
  522. {
  523. var client = _azureStorage.GetBlobContainerClient(sid);
  524. var size = await client.GetBlobsCatalogSize();
  525. await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", sid, size.Item1);
  526. foreach (var key in size.Item2.Keys)
  527. {
  528. await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{sid}", key);
  529. await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{sid}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
  530. }
  531. space.useSize = (long)size.Item1;
  532. space.tSize = teach;
  533. space.catalogSize = size.Item2;
  534. schoolSpace.space = space;
  535. schoolSpaces.Add(schoolSpace);
  536. continue;
  537. }
  538. }
  539. return Ok(new { state = 200, schoolSpaces });
  540. }
  541. /// <summary>
  542. /// 移交学校顾问
  543. /// </summary>
  544. /// <param name="jsonElement"></param>
  545. /// <returns></returns>
  546. [HttpPost("get-shift")]
  547. public async Task<IActionResult> GetShift(JsonElement jsonElement)
  548. {
  549. var (_tmdId, _tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  550. if (!jsonElement.TryGetProperty("school", out JsonElement _school)) return BadRequest();
  551. //if (!jsonElement.TryGetProperty("teacher", out JsonElement _teacher)) return BadRequest();
  552. if (!jsonElement.TryGetProperty("shiftTeacher", out JsonElement _shiftTeacher)) return BadRequest();
  553. jsonElement.TryGetProperty("site", out JsonElement site);
  554. var cosmosClient = _azureCosmos.GetCosmosClient();
  555. var tableClient = _azureStorage.GetCloudTableClient();
  556. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  557. if ($"{site}".Equals(BIConst.Global))
  558. {
  559. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  560. tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
  561. blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
  562. }
  563. SchoolTeacher schoolTeacher = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemAsync<SchoolTeacher>($"{_tmdId}", new PartitionKey($"Teacher-{_school}"));
  564. if (schoolTeacher.roles.IsNotEmpty() && schoolTeacher.roles.Contains("assist"))
  565. {
  566. schoolTeacher.roles.Remove("assist");
  567. SchoolTeacher newSchoolTeacher = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemAsync<SchoolTeacher>($"{_shiftTeacher}", new PartitionKey($"Teacher-{_school}"));
  568. if (!newSchoolTeacher.roles.Contains("assist"))
  569. {
  570. newSchoolTeacher.roles.Add("assist");
  571. newSchoolTeacher = await cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<SchoolTeacher>(newSchoolTeacher, $"{_shiftTeacher}", new PartitionKey($"Teacher-{_school}"));
  572. }
  573. await cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<SchoolTeacher>(schoolTeacher, $"{_tmdId}", new PartitionKey($"Teacher-{_school}"));
  574. School schoolBase = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemAsync<School>($"{_school}", new PartitionKey($"Base"));
  575. //发送消息实体
  576. string shiftCode = "shift-assist";
  577. Notification notification = new Notification
  578. {
  579. hubName = "hita",
  580. type = "msg",
  581. from = $"BI:{_option.Location}:{_school}",
  582. to = new List<string> { $"{_shiftTeacher}" },
  583. label = $"{shiftCode}_school",
  584. body = new { location = _option.Location, biz = shiftCode, tmdid = $"{_tmdId}", tmdname = $"{_tmdName}", status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
  585. expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
  586. };
  587. if (notification != null)
  588. {
  589. var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
  590. var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
  591. var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
  592. var location = _option.Location;
  593. await _notificationService.SendNotification(clientID, clientSecret, location, url, notification);//站内发送消息
  594. }
  595. //保存操作记录
  596. //await _azureStorage.SaveBILog("schoolTeacher-add", $"{_tmdName}【{_tmdId}】移交顾问给{newSchoolTeacher.name}【{newSchoolTeacher.id}】", _dingDing, httpContext: HttpContext);
  597. await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "schoolTeacher-add", $"{_tmdName}【{_tmdId}】移交顾问给{newSchoolTeacher.name}【{newSchoolTeacher.id}】", _dingDing, httpContext: HttpContext);
  598. return Ok(new { state = 200 });
  599. }
  600. else { return Ok(new { status = 201, msg = $"{_tmdName}【{_tmdId}】账号不是顾问" }); }
  601. }
  602. /// <summary>
  603. /// 修改顾问学校
  604. /// </summary>
  605. /// <param name="jsonElement"></param>
  606. /// <returns></returns>
  607. [ProducesDefaultResponseType]
  608. [AuthToken(Roles = "admin,rdc")]
  609. [HttpPost("set-aistschool")]
  610. public async Task<IActionResult> SetAssistSchool(JsonElement jsonElement)
  611. {
  612. try
  613. {
  614. if (!jsonElement.TryGetProperty("partitionKey", out JsonElement parKey)) return BadRequest();
  615. jsonElement.TryGetProperty("userId", out JsonElement userId);
  616. jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
  617. if (!jsonElement.TryGetProperty("schoolIds", out JsonElement jsSchoolIds)) return BadRequest();
  618. if (!jsonElement.TryGetProperty("busy", out JsonElement busy)) return BadRequest();
  619. jsonElement.TryGetProperty("site", out JsonElement site);
  620. List<string> schoolIds = jsSchoolIds.ToObject<List<string>>();
  621. var table = _azureStorage.GetCloudTableClient().GetTableReference("BIDDUserInfo");
  622. var cosmosClient = _azureCosmos.GetCosmosClient();
  623. string divide = _option.Location;
  624. if ($"{site}".Equals(BIConst.Global))
  625. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  626. Dictionary<string, object> dic = new() { { "PartitionKey", $"{parKey}" } };
  627. if (!string.IsNullOrEmpty($"{userId}"))
  628. {
  629. dic.Add("userId", $"{userId}");
  630. }
  631. if (string.IsNullOrEmpty($"{userId}") && string.IsNullOrEmpty($"{tmdId}"))
  632. {
  633. return Ok(new { state = 400, msg = "钉钉账户或醍摩豆账户需要至少要传一个!" });
  634. }
  635. Dictionary<string, List<string>> noSchools = new();
  636. List<DingDingUserInfo> ddUserInfoList = await table.FindListByDict<DingDingUserInfo>(dic);
  637. List<DingDingUserInfo> updUsers = new();
  638. if (ddUserInfoList.Count > 0)
  639. {
  640. foreach (var ddInfo in ddUserInfoList)
  641. {
  642. if (schoolIds.Count > 0)
  643. {
  644. if (string.IsNullOrEmpty(ddInfo.tmdId))
  645. {
  646. var coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", $"{ddInfo.mobile}" } }, _option.Location, _configuration);
  647. if (coreUser != null && coreUser.id != null)
  648. {
  649. ddInfo.tmdId = coreUser.id;
  650. ddInfo.tmdName = coreUser.name;
  651. ddInfo.tmdMobile = coreUser.mobile;
  652. ddInfo.picture = coreUser.picture;
  653. ddInfo.mail = coreUser.mail;
  654. }
  655. else return Ok(new { state = 404, msg = "依据钉钉手机号未找到醍摩豆账号!" });
  656. //List<string> moblie = new() { $"{ddInfo.mobile}" };
  657. //var content = new StringContent(moblie.ToJsonString(), Encoding.UTF8, "application/json");
  658. //string json = await _coreAPIHttpService.GetUserInfos(content);
  659. //if (!string.IsNullOrEmpty(json))
  660. //{
  661. // List<JsonElement> json_id = json.ToObject<List<JsonElement>>();
  662. // foreach (var tmd in json_id)
  663. // {
  664. // ddInfo.tmdId = tmd.GetProperty("id").ToString();
  665. // ddInfo.tmdName = tmd.GetProperty("name").ToString();
  666. // ddInfo.tmdMobile = tmd.GetProperty("mobile").ToString();
  667. // ddInfo.picture = tmd.GetProperty("picture").ToString();
  668. // ddInfo.mail = tmd.GetProperty("mail").ToString();
  669. // }
  670. //}
  671. //else return Ok(new { state = 404, msg = "依据钉钉手机号未找到醍摩豆账号!" });
  672. }
  673. List<string> noSchool = await SchoolWay.SchoolAdviser(cosmosClient, ddInfo, schoolIds, $"{busy}");
  674. if (noSchool.Count > 0)
  675. {
  676. noSchools.Add(ddInfo.tmdId, noSchool);
  677. }
  678. }
  679. List<string> userSchoolAdv = new(ddInfo.schoolIds.Split("|", StringSplitOptions.RemoveEmptyEntries));
  680. if ($"{busy}".Equals("add"))
  681. {
  682. userSchoolAdv.AddRange(schoolIds);
  683. ddInfo.schoolIds = userSchoolAdv.Count > 0 ? string.Join("|", userSchoolAdv) : "";
  684. }
  685. if ($"{busy}".Equals("del"))
  686. {
  687. var temp = userSchoolAdv.Where(p => !schoolIds.Any(x => x == p)).ToList();
  688. ddInfo.schoolIds = temp.Count > 0 ? string.Join("|", temp) : "";
  689. }
  690. updUsers.Add(ddInfo);
  691. }
  692. }
  693. updUsers = await table.SaveOrUpdateAll(updUsers);
  694. if (noSchools.Count > 0)
  695. return Ok(new { state = 201, recUsers = updUsers, noSchools });
  696. else
  697. return Ok(new { state = 200, recUsers = updUsers });
  698. }
  699. catch (Exception ex)
  700. {
  701. await _dingDing.SendBotMsg($"BI,{_option.Location} /batchschool/set-aistschool \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  702. return BadRequest();
  703. }
  704. }
  705. /// <summary>
  706. /// 依据学校ID查学校管理员信息
  707. /// </summary>
  708. /// <param name="jsonElement"></param>
  709. /// <returns></returns>
  710. [HttpPost("get-scmanage")]
  711. public async Task<IActionResult> GetSchoolManage(JsonElement jsonElement)
  712. {
  713. if (!jsonElement.TryGetProperty("scId", out JsonElement scId)) return BadRequest();
  714. jsonElement.TryGetProperty("site", out JsonElement site);
  715. var cosmosClient = _azureCosmos.GetCosmosClient();
  716. if ($"{site}".Equals(BIConst.Global))
  717. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  718. List<BaseInfo> scManages = new();
  719. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<BaseInfo>(queryText: $"select c.id,c.name,c.picture from c where ARRAY_CONTAINS(c.roles,'admin',true) and c.code='Teacher-{scId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{scId}") }))
  720. {
  721. scManages.Add(item);
  722. }
  723. return Ok(new { state = RespondCode.Ok, scManages });
  724. }
  725. /// <summary>
  726. /// 设置学校管理员
  727. /// </summary>
  728. /// <param name="jsonElement"></param>
  729. /// <returns></returns>
  730. [ProducesDefaultResponseType]
  731. [AuthToken(Roles = "admin,rdc")]
  732. [HttpPost("set-manage")]
  733. public async Task<IActionResult> SetSchoolManage(JsonElement jsonElement)
  734. {
  735. try
  736. {
  737. var (_tmdId, _tmdName, _, _, _, _) = HttpJwtAnalysis.JwtXAuthBI(HttpContext.GetXAuth("AuthToken"), _option);
  738. if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
  739. if (!jsonElement.TryGetProperty("tmdName", out JsonElement tmdName)) return BadRequest();
  740. jsonElement.TryGetProperty("tmdPic", out JsonElement picture);
  741. if (!jsonElement.TryGetProperty("scId", out JsonElement schoolId)) return BadRequest();
  742. if (!jsonElement.TryGetProperty("scName", out JsonElement schoolName)) return BadRequest();
  743. jsonElement.TryGetProperty("scPic", out JsonElement scpicture);
  744. jsonElement.TryGetProperty("site", out JsonElement site);
  745. var cosmosClient = _azureCosmos.GetCosmosClient();
  746. var tableClient = _azureStorage.GetCloudTableClient();
  747. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  748. if ($"{site}".Equals(BIConst.Global))
  749. {
  750. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  751. tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
  752. blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
  753. }
  754. StringBuilder strMsg = new($"{_tmdName}【{_tmdId}】账户将{tmdName}【{tmdId}】");
  755. Teacher teacher = null;
  756. SchoolTeacher schoolTeacher = null;
  757. var resTeacher = await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync($"{tmdId}", new PartitionKey($"Base"));
  758. if (resTeacher.Status == 200)
  759. {
  760. using var tchJson = await JsonDocument.ParseAsync(resTeacher.ContentStream);
  761. teacher = tchJson.ToObject<Teacher>();
  762. var existArea = teacher.schools.Find(f => f.schoolId.Equals($"{schoolId}"));
  763. if (existArea == null)
  764. {
  765. teacher.schools.Add(new Teacher.TeacherSchool { schoolId = $"{schoolId}", name = $"{schoolName}", status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), picture = string.IsNullOrEmpty($"{scpicture}") ? "" : $"{scpicture}", areaId = "" });
  766. teacher = await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
  767. strMsg.Append($"账户基础信息添加学校,");
  768. }
  769. }
  770. else
  771. {
  772. teacher.id = $"{tmdId}";
  773. teacher.name = $"{tmdName}";
  774. teacher.picture = string.IsNullOrEmpty($"{picture}") ? "" : $"{picture}";
  775. teacher.pk = "Base";
  776. teacher.code = "Base";
  777. teacher.size = 1;
  778. teacher.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  779. //教师存在,在该教师信息中添加要管理的学校信息
  780. teacher.schools.Add(new Teacher.TeacherSchool { schoolId = $"{schoolId}", name = $"{schoolName}", status = "join", time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), picture = string.IsNullOrEmpty($"{scpicture}") ? "" : $"{scpicture}", areaId = "" });
  781. teacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey("Base"));
  782. strMsg.Append($"添加基础信息,并添加学校");
  783. }
  784. if (teacher != null)
  785. {
  786. var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync($"{tmdId}", new PartitionKey($"Teacher-{schoolId}"));
  787. if (response.Status == 200)
  788. {
  789. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  790. schoolTeacher = json.ToObject<SchoolTeacher>();
  791. if (!schoolTeacher.roles.Contains("admin"))
  792. {
  793. schoolTeacher.roles.Add("admin");
  794. schoolTeacher = await cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<SchoolTeacher>(schoolTeacher, schoolTeacher.id, new PartitionKey($"Teacher-{schoolId}"));
  795. strMsg.Append($"设置管理员,学校信息{schoolName}【{schoolId}】");
  796. }
  797. else
  798. return Ok(new { state = RespondCode.Conflict, schoolTeacher = "已经是该校的管理人员" });
  799. }
  800. else
  801. {
  802. schoolTeacher = new()
  803. {
  804. id = $"{tmdId}",
  805. code = $"Teacher-{schoolId}",
  806. roles = new List<string> { "admin", "teacher" },
  807. job = "管理员",
  808. name = $"{tmdName}",
  809. picture = string.IsNullOrEmpty($"{picture}") ? "" : $"{picture}",
  810. status = "join",
  811. createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
  812. pk = "Teacher",
  813. ttl = -1
  814. };
  815. schoolTeacher = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey($"Teacher-{schoolId}"));
  816. strMsg.Append($"新建学校管理员,学校信息{schoolName}【{schoolId}】");
  817. }
  818. }
  819. //保存操作记录
  820. await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "schoolTeacher-add", $"{_tmdName}【{_tmdId}】账户创建{tmdName}【{tmdName}】账户,并设学校管理员。学校ID:{schoolId}。", _dingDing, httpContext: HttpContext);
  821. return Ok(new { state = RespondCode.Ok, teacher, schoolTeacher });
  822. }
  823. catch (Exception ex)
  824. {
  825. await _dingDing.SendBotMsg($"BI,{_option.Location} /batchschool/set-schoolme \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  826. return BadRequest();
  827. }
  828. }
  829. /// <summary>
  830. /// 移除学校管理员
  831. /// </summary>
  832. /// <param name="jsonElement"></param>
  833. /// <returns></returns>
  834. [ProducesDefaultResponseType]
  835. [AuthToken(Roles = "admin,rdc")]
  836. [HttpPost("del-manage")]
  837. public async Task<IActionResult> DelSchoolManage(JsonElement jsonElement)
  838. {
  839. if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
  840. if (!jsonElement.TryGetProperty("scId", out JsonElement scId)) return BadRequest();
  841. jsonElement.TryGetProperty("site", out JsonElement site);
  842. var cosmosClient = _azureCosmos.GetCosmosClient();
  843. if ($"{site}".Equals(BIConst.Global))
  844. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  845. SchoolTeacher scTeacher = null;
  846. var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync($"{tmdId}", new PartitionKey($"Teacher-{scId}"));
  847. if (response.Status == 200)
  848. {
  849. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  850. scTeacher = json.ToObject<SchoolTeacher>();
  851. if (scTeacher.roles.Contains("admin"))
  852. {
  853. scTeacher.roles.Remove("admin");
  854. scTeacher = await cosmosClient.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<SchoolTeacher>(scTeacher, scTeacher.id, new PartitionKey($"Teacher-{scId}"));
  855. }
  856. else
  857. return Ok(new { state = RespondCode.NotFound, msg = "该账户不是管理员" });
  858. }
  859. else
  860. return Ok(new { state = RespondCode.NotFound, msg = "未找到醍摩豆管理员信息" });
  861. return Ok(new { state = RespondCode.Ok, scTeacher });
  862. }
  863. /// <summary>
  864. /// 删除学校、学校相关的教师、学生
  865. /// </summary>
  866. /// <param name="jsonElement"></param>
  867. /// <returns></returns>
  868. [ProducesDefaultResponseType]
  869. [AuthToken(Roles = "admin,rdc")]
  870. [HttpPost("set-del")]
  871. public async Task<IActionResult> DelSchool(JsonElement jsonElement)
  872. {
  873. try
  874. {
  875. if (!jsonElement.TryGetProperty("schoolId", out JsonElement schoolId)) return BadRequest();
  876. List<string> schools = schoolId.ToObject<List<string>>();
  877. jsonElement.TryGetProperty("site", out JsonElement site);
  878. string _auth = HttpContext.GetXAuth("AuthToken");
  879. var (tmdId, tmdName, pic, did, dname, dpic) = HttpJwtAnalysis.JwtXAuthBI(_auth, _option);
  880. var cosmosClient = _azureCosmos.GetCosmosClient();
  881. var tableClient = _azureStorage.GetCloudTableClient();
  882. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  883. if ($"{site}".Equals(BIConst.Global))
  884. {
  885. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  886. tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
  887. blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
  888. }
  889. StringBuilder msg = new();
  890. List<DelSchoolRel> delSchoolRels = new();
  891. foreach (var tempId in schools)
  892. {
  893. List<string> scTchIds = new();
  894. List<string> scStuIds = new();
  895. string scTecSql = $"select value(c.id) from c where ARRAY_LENGTH(c.roles) > 0 and c.status = 'join'";
  896. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: scTecSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{tempId}") }))
  897. {
  898. scTchIds.Add(item);
  899. }
  900. string scStuSql = $"select value(c.id) from c";
  901. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Student").GetItemQueryIterator<string>(queryText: scStuSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{tempId}") }))
  902. {
  903. scStuIds.Add(item);
  904. }
  905. var response = await cosmosClient.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync($"{tempId}", new PartitionKey($"Base"));
  906. if (response.Status == 204)
  907. msg.AppendLine($"{tmdName}【{tmdId}】删除学校,删除状态:{response.Status},删除ID:{tempId}");
  908. else
  909. delSchoolRels.Add(new DelSchoolRel() { id = $"{tempId}", code = "Base", type = 1, status = response.Status });
  910. foreach (var item in scTchIds)
  911. {
  912. var tchRespnse = await cosmosClient.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync($"{item}", new PartitionKey($"Teacher-{tempId}"));
  913. if (tchRespnse.Status == 204)
  914. msg.AppendLine($"删除教师,删除状态:{tchRespnse.Status},删除ID:{item}");
  915. else
  916. delSchoolRels.Add(new DelSchoolRel() { id = $"{item}", code = $"Teacher-{tempId}", type = 2, status = response.Status });
  917. }
  918. foreach (var item in scStuIds)
  919. {
  920. var stuRespnse = await cosmosClient.GetContainer("TEAMModelOS", "Student").DeleteItemStreamAsync($"{item}", new PartitionKey($"Base-{tempId}"));
  921. if (stuRespnse.Status == 204)
  922. msg.AppendLine($"删除学生,删除状态:{stuRespnse.Status},删除ID:{item}");
  923. else
  924. delSchoolRels.Add(new DelSchoolRel() { id = $"{item}", code = $"Base-{tempId}", type = 3, status = response.Status });
  925. }
  926. }
  927. //string scTecSql = $"select value(c.id) from c where ARRAY_LENGTH(c.roles) > 0 and c.status = 'join'";
  928. //await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: scTecSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{schoolId}") }))
  929. //{
  930. // scTchIds.Add(item);
  931. //}
  932. //string scStuSql = $"select value(c.id) from c";
  933. //await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<string>(queryText: scStuSql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{schoolId}") }))
  934. //{
  935. // scStuIds.Add(item);
  936. //}
  937. //var response = await cosmosClient.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync($"{schoolId}", new PartitionKey($"Base"));
  938. //if (response.Status == 204)
  939. // msg.AppendLine($"{tmdName}【{tmdId}】删除学校,删除状态:{response.Status},删除ID:{schoolId}");
  940. //else
  941. // delSchoolRels.Add(new DelSchoolRel() { id = $"{schoolId}", code = "Base", type = 1, status = response.Status });
  942. //foreach (var item in scTchIds)
  943. //{
  944. // var tchRespnse = await cosmosClient.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync($"{item}", new PartitionKey($"Teacher-{schoolId}"));
  945. // if (tchRespnse.Status == 204)
  946. // msg.AppendLine($"删除教师,删除状态:{tchRespnse.Status},删除ID:{item}");
  947. // else
  948. // delSchoolRels.Add(new DelSchoolRel() { id = $"{item}", code = $"Teacher-{schoolId}", type = 2, status = response.Status });
  949. //}
  950. //foreach (var item in scStuIds)
  951. //{
  952. // var stuRespnse = await cosmosClient.GetContainer("TEAMModelOS", "Student").DeleteItemStreamAsync($"{item}", new PartitionKey($"Base-{schoolId}"));
  953. // if (stuRespnse.Status == 204)
  954. // msg.AppendLine($"删除学生,删除状态:{stuRespnse.Status},删除ID:{item}");
  955. // else
  956. // delSchoolRels.Add(new DelSchoolRel() { id = $"{item}", code = $"Base-{schoolId}", type = 3, status = response.Status });
  957. //}
  958. //保存操作记录
  959. //await _azureStorage.SaveBILog("set-del", msg.ToString(), _dingDing, httpContext: HttpContext);
  960. await AzureStorageBlobExtensions.SaveBILog(blobClient, tableClient, "set-del", msg.ToString(), _dingDing, httpContext: HttpContext);
  961. if (delSchoolRels.Count > 0)
  962. return Ok(new { state = 201, delSchoolRels });
  963. else
  964. return Ok(new { state = 200 });
  965. }
  966. catch (Exception ex)
  967. {
  968. await _dingDing.SendBotMsg($"BI,{_option.Location} /batchschool/set-del \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  969. return BadRequest();
  970. }
  971. }
  972. /// <summary>
  973. /// 查询所有学校 第三方开放平台关联学校显示所有学校
  974. /// </summary>
  975. /// <param name="jsonElement"></param>
  976. /// <returns></returns>
  977. [HttpPost("get-applyschools")]
  978. public async Task<IActionResult> GetApplySchools(JsonElement jsonElement)
  979. {
  980. jsonElement.TryGetProperty("site", out JsonElement site);
  981. var cosmosClient = _azureCosmos.GetCosmosClient();
  982. var tableClient = _azureStorage.GetCloudTableClient();
  983. var blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public");
  984. if ($"{site}".Equals(BIConst.Global))
  985. {
  986. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  987. tableClient = _azureStorage.GetCloudTableClient(BIConst.Global);
  988. blobClient = _azureStorage.GetBlobContainerClient(containerName: "0-public", BIConst.Global);
  989. }
  990. List<ApplySchool> applySchools = new();
  991. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<ApplySchool>(queryText: "select c.id,c.code,c.name,c.picture from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  992. {
  993. applySchools.Add(item);
  994. }
  995. return Ok(new { state = 200, applySchools });
  996. }
  997. /// <summary>
  998. /// 通过学校Id查询详情 数据管理工具——查询工具
  999. /// </summary>
  1000. /// <returns></returns>
  1001. [HttpPost("get-info")]
  1002. public async Task<IActionResult> GetSchool(JsonElement jsonElement)
  1003. {
  1004. jsonElement.TryGetProperty("schoolId", out JsonElement schoolId);
  1005. jsonElement.TryGetProperty("site", out JsonElement site);
  1006. var cosmosClient = _azureCosmos.GetCosmosClient();
  1007. if ($"{site}".Equals(BIConst.Global))
  1008. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  1009. StringBuilder sqlTxt = new StringBuilder("select * from c");
  1010. if (!string.IsNullOrEmpty($"{schoolId}"))
  1011. {
  1012. sqlTxt.Append($" where c.id='{schoolId}'");
  1013. }
  1014. List<School> schools = new();
  1015. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  1016. {
  1017. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  1018. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  1019. {
  1020. foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
  1021. {
  1022. schools.Add(obj.ToObject<School>());
  1023. }
  1024. }
  1025. }
  1026. return Ok(new { state = 200, schools });
  1027. }
  1028. /// <summary>
  1029. /// 依据区域Id查询区域空间统计
  1030. /// </summary>
  1031. /// <param name="jsonElement"></param>
  1032. /// <returns></returns>
  1033. [ProducesDefaultResponseType]
  1034. [HttpPost("get-spance")]
  1035. public async Task<IActionResult> GetAreaSpace(JsonElement jsonElement)
  1036. {
  1037. jsonElement.TryGetProperty("areaId", out JsonElement areaId);
  1038. jsonElement.TryGetProperty("schoolId", out JsonElement schoolId);
  1039. jsonElement.TryGetProperty("site", out JsonElement site);
  1040. var cosmosClient = _azureCosmos.GetCosmosClient();
  1041. if ($"{site}".Equals(BIConst.Global))
  1042. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  1043. long allSize = 0; //全部大小
  1044. int teacherSpace = 0; //学校分配给教师的空间
  1045. long useSize = 0; //已使用大小
  1046. Dictionary<string, double?> useSpaceInfo = new(); //学校使用详情
  1047. //查询区域所有学校
  1048. if (!string.IsNullOrEmpty($"{areaId}"))
  1049. {
  1050. List<string> schools = new();
  1051. schools = await CommonFind.FindSchoolIds(cosmosClient, $"select c.id from c where c.areaId='{areaId}'", "Base");
  1052. allSize = await CommonFind.FindTotals(cosmosClient, $"select sum(c.size) as totals from c where c.areaId='{areaId}'", new List<string> { "School" }); //区域所有学校空间
  1053. foreach (var school in schools)
  1054. {
  1055. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: $"SELECT sum(c.size) as size FROM c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{school}") }))
  1056. {
  1057. var json = await JsonDocument.ParseAsync(item.ContentStream);
  1058. foreach (var elmt in json.RootElement.GetProperty("Documents").EnumerateArray())
  1059. {
  1060. if (elmt.TryGetProperty("size", out JsonElement _size) && _size.ValueKind.Equals(JsonValueKind.Number))
  1061. {
  1062. teacherSpace += _size.GetInt32();
  1063. break;
  1064. }
  1065. }
  1066. }
  1067. long blobsize = 0;
  1068. RedisValue value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", $"{school}");
  1069. if (!value.IsNullOrEmpty)
  1070. {
  1071. JsonElement record = value.ToString().ToObject<JsonElement>();
  1072. if (record.TryGetInt64(out blobsize))
  1073. {
  1074. }
  1075. }
  1076. else
  1077. {
  1078. var storageClient = _azureStorage.GetBlobContainerClient("school");
  1079. var size = await storageClient.GetBlobsCatalogSize();
  1080. await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", $"{school}", size.Item1);
  1081. foreach (var key in size.Item2.Keys)
  1082. {
  1083. await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Bolb:Catalog:{school}", key);
  1084. await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Bolb:Catalog:school", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
  1085. }
  1086. useSize += size.Item1.Value;
  1087. useSpaceInfo = useSpaceInfo.Concat(size.Item2).GroupBy(g => g.Key).ToDictionary(k => k.Key, k => k.Sum(kvp => kvp.Value)); //lamebda表达式
  1088. //useSpaceInfo = (from e in useSpaceInfo.Concat(size.Item2) group e by e.Key into g select new { Name = g.Key, value = g.Sum(kvp => kvp.Value) }).ToDictionary(item => item.Name, item => item.value); //linq 方式合并
  1089. }
  1090. SortedSetEntry[] Scores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Blob:Catalog:{school}");
  1091. if (Scores != null)
  1092. {
  1093. Dictionary<string, double?> catalog = new();
  1094. foreach (var score in Scores)
  1095. {
  1096. double val = score.Score;
  1097. string key = score.Element.ToString();
  1098. catalog.Add(key, val);
  1099. }
  1100. useSpaceInfo = useSpaceInfo.Concat(catalog).GroupBy(g => g.Key).ToDictionary(k => k.Key, k => k.Sum(kvp => kvp.Value)); //lamebda表达式
  1101. //useSpaceInfo = (from e in useSpaceInfo.Concat(catalog) group e by e.Key into g select new { Name = g.Key, value = g.Sum(kvp => kvp.Value) }).ToDictionary(item => item.Name, item => item.value); //linq 方式合并
  1102. }
  1103. else
  1104. {
  1105. var client = _azureStorage.GetBlobContainerClient("school");
  1106. var size = await client.GetBlobsCatalogSize();
  1107. await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", $"{school}", size.Item1);
  1108. foreach (var key in size.Item2.Keys)
  1109. {
  1110. await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{school}", key);
  1111. await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{school}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
  1112. }
  1113. useSize += size.Item1.Value;
  1114. useSpaceInfo = useSpaceInfo.Concat(size.Item2).GroupBy(g => g.Key).ToDictionary(k => k.Key, k => k.Sum(kvp => kvp.Value)); //lamebda表达式
  1115. //useSpaceInfo = (from e in useSpaceInfo.Concat(size.Item2) group e by e.Key into g select new { Name = g.Key, value = g.Sum(kvp => kvp.Value) }).ToDictionary(item => item.Name, item => item.value); //linq 方式合并
  1116. }
  1117. }
  1118. }
  1119. //查询学校
  1120. if (!string.IsNullOrEmpty($"{schoolId}"))
  1121. {
  1122. allSize = await CommonFind.FindTotals(cosmosClient, $"SELECT c.size as totals FROM c where c.id='{schoolId}'", "School", "Base");
  1123. teacherSpace = await CommonFind.FindTotals(cosmosClient, $"SELECT sum(c.size) as totals FROM c", "School", $"Teacher-{schoolId}");
  1124. long blobsize = 0;
  1125. RedisValue value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", $"{schoolId}");
  1126. if (!value.IsNullOrEmpty)
  1127. {
  1128. JsonElement record = value.ToString().ToObject<JsonElement>();
  1129. if (record.TryGetInt64(out blobsize))
  1130. {
  1131. useSize = blobsize;
  1132. }
  1133. }
  1134. else
  1135. {
  1136. var storageClient = _azureStorage.GetBlobContainerClient("school");
  1137. var size = await storageClient.GetBlobsCatalogSize();
  1138. await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", $"{schoolId}", size.Item1);
  1139. foreach (var key in size.Item2.Keys)
  1140. {
  1141. await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Bolb:Catalog:{schoolId}", key);
  1142. await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Bolb:Catalog:school", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
  1143. }
  1144. useSpaceInfo = size.Item2;
  1145. }
  1146. Dictionary<string, double?> catalog = new();
  1147. SortedSetEntry[] Scores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Blob:Catalog:{schoolId}");
  1148. if (Scores != null)
  1149. {
  1150. foreach (var score in Scores)
  1151. {
  1152. double val = score.Score;
  1153. string key = score.Element.ToString();
  1154. catalog.Add(key, val);
  1155. }
  1156. useSpaceInfo = catalog;
  1157. }
  1158. else
  1159. {
  1160. var client = _azureStorage.GetBlobContainerClient("school");
  1161. var size = await client.GetBlobsCatalogSize();
  1162. await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", $"{schoolId}", size.Item1);
  1163. foreach (var key in size.Item2.Keys)
  1164. {
  1165. await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{schoolId}", key);
  1166. await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{schoolId}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
  1167. }
  1168. useSize = size.Item1.Value;
  1169. useSpaceInfo = size.Item2;
  1170. }
  1171. }
  1172. return Ok(new { state = 200, allSize, useSize, teacherSpace, useSpaceInfo });
  1173. }
  1174. /// <summary>
  1175. /// 依据学校统计
  1176. /// </summary>
  1177. /// <param name="jsonElement"></param>
  1178. /// <returns></returns>
  1179. [HttpPost("get-schoolcnt")]
  1180. public async Task<IActionResult> GetSchoolCnt(JsonElement jsonElement)
  1181. {
  1182. if (!jsonElement.TryGetProperty("schoolId", out JsonElement schoolId)) return BadRequest();
  1183. jsonElement.TryGetProperty("site", out JsonElement site);
  1184. var cosmosClient = _azureCosmos.GetCosmosClient();
  1185. if ($"{site}".Equals(BIConst.Global))
  1186. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  1187. DateTimeOffset dtime = DateTimeOffset.UtcNow;
  1188. var (weekS, weekE) = TimeHelper.GetStartOrEnd(dtime, "week");
  1189. var (lastWeekS, lastWeekE) = TimeHelper.GetStartOrEnd(dtime, "lastweek");
  1190. var (termS, termE) = TimeHelper.GetStartOrEnd(dtime, "term");
  1191. var (lastTermS, lastTermE) = TimeHelper.GetStartOrEnd(dtime, "lastterm");
  1192. var (yearS, yearE) = TimeHelper.GetStartOrEnd(dtime, "year");
  1193. var (lastYearS, lastYearE) = TimeHelper.GetStartOrEnd(dtime, "lastYear");
  1194. int tecCnt = 0;// 教师数量
  1195. int classCnt = 0; //班级
  1196. int stuCnt = 0; //学生
  1197. int roomCnt = 0; //智慧教室
  1198. int lesCnt = 0; //课例总数
  1199. int weekLesCnt = 0; //本周课例
  1200. int lastWeekLesCnt = 0; //上周课例
  1201. int weekACTCnt = 0; //本周活动
  1202. int lastWeekACTCnt = 0; //上周活动
  1203. int termLesCnt = 0; //本学期课例
  1204. int lastTermLesCnt = 0; //上学学期课例
  1205. int termACTCnt = 0; //本学期活动
  1206. int lastTermActCnt = 0; //上学学期活动
  1207. int yearLesCnt = 0; //今年课例
  1208. int lastYearLesCnt = 0; //去年课例
  1209. int yearACTCnt = 0; //今年课例
  1210. int lastYearACTCnt = 0; //去年课例
  1211. SchoolInfo schoolInfo = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<SchoolInfo>($"{schoolId}", new PartitionKey("Base"));
  1212. if (schoolInfo != null)
  1213. {
  1214. var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(schoolInfo.id, new PartitionKey("ProductSum"));
  1215. if (response.Status == 200)
  1216. {
  1217. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  1218. if (json.RootElement.TryGetProperty("serial", out JsonElement serial) && !serial.ValueKind.Equals(JsonValueKind.Null))
  1219. {
  1220. schoolInfo.serial = serial.ToObject<List<ProductSumInfos>>();
  1221. }
  1222. if (json.RootElement.TryGetProperty("service", out JsonElement service) && !service.ValueKind.Equals(JsonValueKind.Null))
  1223. {
  1224. schoolInfo.service = service.ToObject<List<ProductSumInfos>>();
  1225. }
  1226. if (json.RootElement.TryGetProperty("hard", out JsonElement hard) && !hard.ValueKind.Equals(JsonValueKind.Null))
  1227. {
  1228. schoolInfo.hard = hard.ToObject<List<SchoolProductSumDataHard>>();
  1229. }
  1230. }
  1231. schoolInfo.assists = await CommonFind.FindSchoolRoles(cosmosClient, schoolInfo.id, "assist");
  1232. string currencySql = "select value(count(c.id)) from c";
  1233. //schoolInfo.lessonCount = await CommonFind.GetSqlValueCount(cosmosClient, "School", currencySql, $"LessonRecord-{schoolInfo.id}");
  1234. tecCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", currencySql, $"Teacher-{schoolInfo.id}"); // 教师数量
  1235. classCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", currencySql, $"Class-{schoolInfo.id}"); //班级
  1236. stuCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Student", currencySql, $"Base-{schoolInfo.id}"); //学生
  1237. roomCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", currencySql, $"Room-{schoolInfo.id}"); //智慧教室
  1238. lesCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", currencySql, $"LessonRecord-{schoolInfo.id}"); //课例总数
  1239. weekLesCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{currencySql} where c.startTime >= {weekS} and c.startTime<= {weekE}", $"LessonRecord-{schoolInfo.id}"); //本周课例
  1240. lastWeekLesCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{currencySql} where c.startTime >= {lastWeekS} and c.startTime<= {lastWeekE}", $"LessonRecord-{schoolInfo.id}"); //上周课例
  1241. termLesCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{currencySql} where c.startTime >= {termS} and c.startTime <= {termE}", $"LessonRecord-{schoolInfo.id}"); //本学期课例
  1242. lastTermLesCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{currencySql} where c.startTime >= {lastTermS} and c.startTime <= {lastTermE}", $"LessonRecord-{schoolInfo.id}"); //上学学期课例
  1243. yearLesCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{currencySql} where c.startTime >= {yearS} and c.startTime <= {yearE}", $"LessonRecord-{schoolInfo.id}"); //今年课例
  1244. lastYearLesCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{currencySql} where c.startTime >= {lastYearS} and c.startTime <= {lastYearE}", $"LessonRecord-{schoolInfo.id}"); //去年课例
  1245. int ACTCnt = 0; //活动
  1246. foreach (var type in StaticValue.activityTypes)
  1247. {
  1248. ACTCnt += await CommonFind.GetSqlValueCount(cosmosClient, "Common", $"{currencySql} where c.pk='{type}' and c.school='{schoolInfo.id}'");
  1249. weekACTCnt += await CommonFind.GetSqlValueCount(cosmosClient, "Common", $"{currencySql} where c.pk='{type}' and c.school='{schoolInfo.id}' and c.createTime >= {weekS} and c.createTime <= {weekE} "); //本周活动
  1250. lastWeekACTCnt += await CommonFind.GetSqlValueCount(cosmosClient, "Common", $"{currencySql} where c.pk='{type}' and c.school='{schoolInfo.id}' and c.createTime >= {lastWeekS} and c.createTime <= {lastWeekE} "); //上周活动
  1251. termACTCnt += await CommonFind.GetSqlValueCount(cosmosClient, "Common", $"{currencySql} where c.pk='{type}' and c.school='{schoolInfo.id}' and c.createTime >= {termS} and c.createTime <= {termE}", $"LessonRecord-{schoolInfo.id}"); //本学期活动
  1252. lastTermActCnt += await CommonFind.GetSqlValueCount(cosmosClient, "Common", $"{currencySql} where c.pk='{type}' and c.school='{schoolInfo.id}' and c.createTime >= {lastTermS} and c.createTime <= {lastTermE}", $"LessonRecord-{schoolInfo.id}"); //上学学期活动
  1253. yearACTCnt += await CommonFind.GetSqlValueCount(cosmosClient, "Common", $"{currencySql} where c.pk='{type}' and c.school='{schoolInfo.id}' and c.createTime >= {yearS} and c.createTime <= {yearE}", $"LessonRecord-{schoolInfo.id}"); //今年活动
  1254. lastYearACTCnt += await CommonFind.GetSqlValueCount(cosmosClient, "Common", $"{currencySql} where c.pk='{type}' and c.school='{schoolInfo.id}' and c.createTime >= {lastYearS} and c.createTime <= {lastYearE}", $"LessonRecord-{schoolInfo.id}"); //去年活动
  1255. }
  1256. return Ok(new { state = RespondCode.Ok, tecCnt, classCnt, stuCnt, roomCnt, lesCnt, weekLesCnt, lastWeekLesCnt, weekACTCnt, lastWeekACTCnt, termLesCnt, lastTermLesCnt, termACTCnt, lastTermActCnt, yearLesCnt, lastYearLesCnt, yearACTCnt, lastYearACTCnt, schoolInfo, ACTCnt });
  1257. }
  1258. else
  1259. return Ok(new { state = RespondCode.NotFound, msg = "未找到该学校信息!" });
  1260. }
  1261. /// <summary>
  1262. /// 通过学校Id 统计学校信息
  1263. /// </summary>
  1264. /// <param name="jsonElement"></param>
  1265. /// <returns></returns>
  1266. [HttpPost("get-analyse")]
  1267. public async Task<IActionResult> GetAnalyse(JsonElement jsonElement)
  1268. {
  1269. if (!jsonElement.TryGetProperty("schoolId", out JsonElement schoolId)) return BadRequest();
  1270. jsonElement.TryGetProperty("site", out JsonElement site);
  1271. var cosmosClient = _azureCosmos.GetCosmosClient();
  1272. if ($"{site}".Equals(BIConst.Global))
  1273. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  1274. RecSchool recSchool = new();
  1275. var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync($"{schoolId}", new PartitionKey("Base"));
  1276. if (response.Status == 200)
  1277. {
  1278. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  1279. recSchool = json.ToObject<RecSchool>();
  1280. }
  1281. else return Ok(new { state = RespondCode.NotFound, msg = "未找到该学校" });
  1282. DateTimeOffset dateTime = DateTimeOffset.UtcNow;
  1283. var (days, daye) = TimeHelper.GetStartOrEnd(dateTime);
  1284. var (lastDays, lastDaye) = TimeHelper.GetStartOrEnd(dateTime.AddDays(-1));
  1285. var (years, yeare) = TimeHelper.GetStartOrEnd(dateTime, "year");
  1286. var (lastYears, lastYeare) = TimeHelper.GetStartOrEnd(dateTime, "lastYear");
  1287. int tchCnt = 0; //教师数量
  1288. int stuCnt = 0; //学校数量
  1289. int roomCnt = 0; //智慧教室数量
  1290. int lessAllCant = 0; //课例总数
  1291. int lessLastdayCnt = 0; //昨天的课例
  1292. int lessDayCnt = 0; //今天的课例
  1293. int lessLastYearCnt = 0; //去年的课例
  1294. int lessYearCnt = 0; //今年的课例
  1295. int allInterCnt = 0; //所有互动
  1296. int lastDayInterCnt = 0; // 昨天课例互动
  1297. int interCnt = 0; // 今天课例互动
  1298. int lastYearInterCnt = 0; // 去年课例互动
  1299. int yearInterCnt = 0; // 今年课例互动
  1300. int allActCnt = 0; //所有活动
  1301. int lastActCnt = 0; //昨天活动
  1302. int actCnt = 0; //今天活动
  1303. int lastYearActCnt = 0; //去年活动
  1304. int yearActCnt = 0; //今年活动
  1305. string commSql = "select value(count(c.id)) from c ";
  1306. tchCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", commSql, $"Teacher-{schoolId}");
  1307. stuCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Student", commSql, $"Base-{schoolId}");
  1308. roomCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", commSql, $"Room-{schoolId}");
  1309. lessAllCant = await CommonFind.GetSqlValueCount(cosmosClient, "School", commSql, $"LessonRecord-{schoolId}");
  1310. string lessCode = $"LessonRecord-{schoolId}";
  1311. string lessLastdaySql = $"{commSql} where c.startTime >= {lastDays} and c.startTime <= {lastDays} ";
  1312. lessLastdayCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lessLastdaySql, lessCode);
  1313. string lessDaySql = $"{commSql} where c.startTime >= {days} and c.startTime <= {daye} ";
  1314. lessDayCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lessDaySql, lessCode);
  1315. string lessLastYarSql = $"{commSql} where c.startTime >= {lastYears} and c.startTime <= {lastYeare} ";
  1316. lessLastYearCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lessLastYarSql, lessCode);
  1317. string lessYearSql = $"{commSql} where c.startTime >= {years} and c.startTime <= {yeare} ";
  1318. lessYearCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lessYearSql, lessCode);
  1319. //课例互动
  1320. string strInterSql = $"select value(sum(c.clientInteractionAverge)) from c";
  1321. allInterCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", strInterSql, lessCode);
  1322. string lastdayInterSql = $"{strInterSql} where c.startTime >= { lastDays} and c.startTime <= {lastDays} ";
  1323. lastDayInterCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lastdayInterSql, lessCode);
  1324. string dayInterSql = $"{strInterSql} where c.startTime >= { days} and c.startTime <= {daye} ";
  1325. interCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", dayInterSql, lessCode);
  1326. string lastYarInterSql = $"{strInterSql} where c.startTime >= { lastYears} and c.startTime <= {lastYeare} ";
  1327. lastYearInterCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lastYarInterSql, lessCode);
  1328. string yearInterSql = $"{strInterSql} where c.startTime >= { years} and c.startTime <= {yeare} ";
  1329. yearInterCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", yearInterSql, lessCode);
  1330. //活动
  1331. allActCnt = await ActivityWay.GetCnt(cosmosClient, $"and c.school='{schoolId}'");
  1332. string lastActSql = $" and c.school='{schoolId}' and c.createTime >= {lastDays} and c.createTime <= {lastDays}";
  1333. lastActCnt = await ActivityWay.GetCnt(cosmosClient, lastActSql);
  1334. string actSql = $" and c.school='{schoolId}' and c.createTime >= {days} and c.createTime <= {daye}";
  1335. actCnt = await ActivityWay.GetCnt(cosmosClient, actSql);
  1336. string lastYearActSql = $" and c.school='{schoolId}' and c.createTime >= {lastYears} and c.createTime <= {lastYeare}";
  1337. lastYearActCnt = await ActivityWay.GetCnt(cosmosClient, lastYearActSql);
  1338. string yearActSql = $" and c.school='{schoolId}' and c.createTime >= {years} and c.createTime <= {yeare}";
  1339. yearActCnt = await ActivityWay.GetCnt(cosmosClient, yearActSql);
  1340. return Ok(new { state = 200, recSchool, tchCnt, stuCnt, roomCnt, lessAllCant, lessLastdayCnt, lessDayCnt, lessLastYearCnt, lessYearCnt, allInterCnt, lastDayInterCnt, interCnt, lastYearInterCnt, yearInterCnt, allActCnt, lastActCnt, actCnt, lastYearActCnt, yearActCnt });
  1341. }
  1342. /// <summary>
  1343. /// 学校每周课例趋势
  1344. /// </summary>
  1345. /// <param name="jsonElement"></param>
  1346. /// <returns></returns>
  1347. [HttpPost("get-schooldate")]
  1348. public async Task<IActionResult> GetSchoolDate(JsonElement jsonElement)
  1349. {
  1350. if (!jsonElement.TryGetProperty("schoolId", out JsonElement schoolId)) return BadRequest();
  1351. jsonElement.TryGetProperty("site", out JsonElement site);
  1352. var cosmosClient = _azureCosmos.GetCosmosClient();
  1353. if ($"{site}".Equals(BIConst.Global))
  1354. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  1355. List<double> weekTrend = new();
  1356. int year = DateTimeOffset.UtcNow.Year;
  1357. int dayOfweek = (int)DateTimeOffset.Parse($"{year}-1-1").DayOfWeek;
  1358. int currentTime = DateTimeOffset.UtcNow.DayOfYear / 7 + 1;
  1359. int currentTime1 = DateTimeOffset.UtcNow.DayOfYear / 7;
  1360. //获取当前学期所有的课程记录
  1361. List<LessAnalyse> records = new List<LessAnalyse>();
  1362. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<LessAnalyse>(queryText: $"select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord-{schoolId}") }))
  1363. {
  1364. records.Add(item);
  1365. }
  1366. List<(string name, string periodId, int count)> grades = LessonStatisWay.GetGradeCount(records);
  1367. var subs = records.GroupBy(x => x.subjectId).Where(w => !string.IsNullOrEmpty(w.Key)).Select(y => new { key = y.Key, count = y.ToList().Count }).ToList();
  1368. var gradeCnt = grades.Select(x => new { x.name, x.periodId, value = x.count });
  1369. var subCnt = subs.Select(x => new { name = x.key, value = x.count });
  1370. List<LessonCount> scount = new();
  1371. List<LessonCount> tcount = new();
  1372. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<LessonCount>(queryText: "select value(c) from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonCount-{schoolId}-{year}") }))
  1373. {
  1374. scount.Add(item);
  1375. }
  1376. List<string> teacIds = await CommonFind.FindRolesId(cosmosClient, new List<string>() { $"{schoolId}" });
  1377. foreach (var tId in teacIds)
  1378. {
  1379. var sqlTxtt = $"select value(c) from c where c.id='{tId}'";
  1380. await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<LessonCount>(queryText: sqlTxtt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonCount-{year}") }))
  1381. {
  1382. tcount.Add(item);
  1383. }
  1384. }
  1385. int days = (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? days = 366 : days = 365;
  1386. List<List<double>> lessons = new();
  1387. if (scount.Count > 0)
  1388. {
  1389. foreach (LessonCount item in scount)
  1390. {
  1391. lessons.Add(item.beginCount);
  1392. }
  1393. }
  1394. if (tcount.Count > 0)
  1395. {
  1396. foreach (LessonCount item in tcount)
  1397. {
  1398. lessons.Add(item.beginCount);
  1399. }
  1400. }
  1401. if (lessons.Count > 0)
  1402. {
  1403. var bmatrix = DenseMatrix.OfColumns(lessons);
  1404. //开学第一周周内开课
  1405. if (dayOfweek == 0)
  1406. {
  1407. dayOfweek = 7;
  1408. }
  1409. //第一周多少天
  1410. var dd = 7 - dayOfweek + 1;
  1411. //一年有几周
  1412. int sweeks = days / 7;
  1413. //查询天数
  1414. int dayYear = 0;
  1415. if (currentTime > 0)
  1416. {
  1417. for (int i = 0; i <= currentTime; i++)
  1418. {
  1419. if (i == 0)
  1420. {
  1421. var bsum = bmatrix.SubMatrix(dayYear, dd, 0, bmatrix.ColumnCount).ColumnSums().Sum();
  1422. dayYear += dd;
  1423. //weeks.Add(i, bsum);
  1424. weekTrend.Add(bsum);
  1425. }
  1426. else
  1427. {
  1428. var bsum = bmatrix.SubMatrix(dayYear, 7, 0, bmatrix.ColumnCount).ColumnSums().Sum();
  1429. dayYear += 7;
  1430. //weeks.Add(i, bsum);
  1431. weekTrend.Add(bsum);
  1432. }
  1433. }
  1434. }
  1435. //最后一周是否有余
  1436. int stary = days - dayYear;
  1437. if (stary > 0 && stary < 7)
  1438. {
  1439. var bsum = bmatrix.SubMatrix(dayYear, stary - 1, 0, bmatrix.ColumnCount).ColumnSums().Sum();
  1440. //weeks.Add((sweeks + 1), bsum);
  1441. weekTrend.Add(bsum);
  1442. }
  1443. }
  1444. return Ok(new { state = 200, gradeCnt, subCnt, weekTrend });
  1445. }
  1446. /// <summary>
  1447. /// 顾问学校基础统计、以及排行
  1448. /// </summary>
  1449. /// <param name="jsonElement"></param>
  1450. /// <returns></returns>
  1451. [ProducesDefaultResponseType]
  1452. [HttpPost("get-assisscbase")]
  1453. public async Task<IActionResult> GetAssistSchoolCnt(JsonElement jsonElement)
  1454. {
  1455. if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
  1456. jsonElement.TryGetProperty("site", out JsonElement site);
  1457. var cosmosClient = _azureCosmos.GetCosmosClient();
  1458. if ($"{site}".Equals(BIConst.Global))
  1459. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  1460. DateTimeOffset dateTime = DateTimeOffset.UtcNow;
  1461. int scAllCnt = 0; //学校
  1462. int tchAllCnt = 0; //教师数量
  1463. int tchMonthCnt = 0; //教师本月新增
  1464. int stuAllCnt = 0; //所有学校学生
  1465. int lessAllCnt = 0; //课例总数
  1466. int lessMthCnt = 0; //本月新增
  1467. List<ScRankCnt> scRankCnts = new(); //学校开课、上传, 课例排名
  1468. var (start, end) = TimeHelper.GetStartOrEnd(dateTime, "month");
  1469. List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
  1470. if (schoolIds.Count > 0)
  1471. {
  1472. string scIdSql = BICommonWay.ManyScSql("c.schoolId", schoolIds);
  1473. string stuSql = $"select value(count(c.id)) from c where {scIdSql}";
  1474. stuAllCnt = await CommonFind.GetSqlValueCount(cosmosClient, "Student", stuSql);
  1475. string scSql = BICommonWay.ManyScSql("c.school", schoolIds);
  1476. string lessMoSql = $"select value(count(c.id)) from c where c.pk='LessonRecord' and {scSql} and c.startTime >= {start} and c.startTime <= {end}";
  1477. lessMthCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lessMoSql);
  1478. List<SchoolBase> scInfos = new();
  1479. string scInfoSql = $"select c.id,c.name,c.code,c.picture from c ";
  1480. scInfos = await CommonFind.GetObject<SchoolBase>(cosmosClient, "School", scInfoSql, "Base", schoolIds);
  1481. List<string> tchMonIds = new();
  1482. foreach (var item in scInfos)
  1483. {
  1484. ScRankCnt lessRankCnt = new() { id = item.id, name = item.name, code = item.code, picture = item.picture };
  1485. string tchSql = $"select value(count(c.id)) from c where array_contains(c.roles,'teacher',true) and c.createTime >= {start} and c.createTime <= {end}";
  1486. tchMonthCnt += await CommonFind.GetSqlValueCount(cosmosClient, "School", tchSql, $"Teacher-{item.id}");
  1487. string tchAllSql = $"select value(count(c.id)) from c where ARRAY_CONTAINS(c.roles,'teacher',true) and c.status = 'join'";
  1488. tchAllCnt += await CommonFind.GetSqlValueCount(cosmosClient, "School", tchAllSql, $"Teacher-{item.id}");
  1489. string lessALLSql = "select value(count(c.id)) from c where c.pk='LessonRecord'";
  1490. lessAllCnt += await CommonFind.GetSqlValueCount(cosmosClient, "School", lessALLSql, $"LessonRecord-{item.id}");
  1491. string lessUpSql = $"select value(count(c.id)) from c where c.pk='LessonRecord' and c.upload = 0";
  1492. lessRankCnt.openCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lessMoSql, $"LessonRecord-{item.id}");
  1493. string lessSql = $"select value(count(c.id)) from c where c.pk='LessonRecord' and c.upload = 1";
  1494. lessRankCnt.lessCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lessSql, $"LessonRecord-{item.id}");
  1495. string interactSql = $"select value(sum(c.clientInteractionCount)) from c where c.pk='LessonRecord'";
  1496. lessRankCnt.interCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", interactSql, $"LessonRecord-{item.id}");
  1497. string actSql = $" and c.school='{item.id}'";
  1498. lessRankCnt.actCnt = await ActivityWay.GetCnt(cosmosClient, actSql);
  1499. scRankCnts.Add(lessRankCnt);
  1500. }
  1501. scAllCnt = schoolIds.Count();
  1502. tchMonthCnt = tchMonIds.Distinct().Count();
  1503. }
  1504. return Ok(new { state = RespondCode.Ok, scAllCnt, tchAllCnt, tchMonthCnt, stuAllCnt, lessAllCnt, lessMthCnt, scRankCnts });
  1505. }
  1506. /// <summary>
  1507. /// 一年学校和多个学校的课例、互动、活动统计分析
  1508. /// </summary>
  1509. /// <param name="jsonElement"></param>
  1510. /// <returns></returns>
  1511. [ProducesDefaultResponseType]
  1512. [HttpPost("get-assissc")]
  1513. public async Task<IActionResult> GetAssisSc(JsonElement jsonElement)
  1514. {
  1515. jsonElement.TryGetProperty("tmdId", out JsonElement tmdId);
  1516. jsonElement.TryGetProperty("schoolId", out JsonElement schooId);
  1517. jsonElement.TryGetProperty("site", out JsonElement site);
  1518. var cosmosClient = _azureCosmos.GetCosmosClient();
  1519. if ($"{site}".Equals(BIConst.Global))
  1520. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  1521. List<YearCnt> yearCnts = new(); //当前的课例,活动,互动统计
  1522. string strSql = "SELECT value(count(c.id)) FROM c where c.pk='LessonRecord'";
  1523. string scSql = null;
  1524. if (!string.IsNullOrEmpty($"{tmdId}") && string.IsNullOrEmpty($"{schooId}"))
  1525. {
  1526. List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
  1527. if (schoolIds.Count == 0) return Ok(new { state = RespondCode.Ok, yearCnts, });
  1528. scSql = BICommonWay.ManyScSql("c.school", schoolIds);
  1529. }
  1530. if (!string.IsNullOrEmpty($"{schooId}") && string.IsNullOrEmpty($"{tmdId}"))
  1531. scSql = $"c.school = '{schooId}'";
  1532. if ((string.IsNullOrEmpty($"{tmdId}") && string.IsNullOrEmpty($"{schooId}")) || (!string.IsNullOrEmpty($"{tmdId}") && !string.IsNullOrEmpty($"{schooId}")))
  1533. return Ok(new { state = RespondCode.ParamsError, msg = "参数错误" });
  1534. List<MonthStartEnd> mthStartEnds = await TimeHelper.GetYearSataMthCtMth(DateTimeOffset.UtcNow);
  1535. if (mthStartEnds.Count > 0)
  1536. {
  1537. foreach (var item in mthStartEnds)
  1538. {
  1539. YearCnt yearCnt = new() { name = item.yearMonth };
  1540. string selessSql = $"{strSql} and {scSql.ToString()} and c.startTime >= { item.start} and c.startTime <= {item.end}";
  1541. yearCnt.lessCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", selessSql);
  1542. string interactSql = $"select value(sum(c.clientInteractionAverge)) from c where c.pk='LessonRecord' and {scSql} and c.startTime >= { item.start} and c.startTime <= {item.end}";
  1543. yearCnt.interCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", interactSql);
  1544. string mthActSql = $" and {scSql} and c.createTime >= {item.start} and c.createTime <= {item.end}";
  1545. yearCnt.actCnt = await ActivityWay.GetCnt(cosmosClient, mthActSql);
  1546. yearCnts.Add(yearCnt);
  1547. }
  1548. }
  1549. return Ok(new { state = RespondCode.Ok, yearCnts, });
  1550. }
  1551. /// <summary>
  1552. /// 顾问学校统计
  1553. /// </summary>
  1554. /// <param name="jsonElement"></param>
  1555. /// <returns></returns>
  1556. [ProducesDefaultResponseType]
  1557. [HttpPost("get-assissccnt")]
  1558. public async Task<IActionResult> GetAssisScCnt(JsonElement jsonElement)
  1559. {
  1560. if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return BadRequest();
  1561. jsonElement.TryGetProperty("site", out JsonElement site);
  1562. var cosmosClient = _azureCosmos.GetCosmosClient();
  1563. if ($"{site}".Equals(BIConst.Global))
  1564. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  1565. DateTimeOffset dateTime = DateTimeOffset.UtcNow;
  1566. var (days, daye) = TimeHelper.GetStartOrEnd(dateTime);
  1567. var (lastDays, lastDaye) = TimeHelper.GetStartOrEnd(dateTime.AddDays(-1));
  1568. var (years, yeare) = TimeHelper.GetStartOrEnd(dateTime, "year");
  1569. var (lastYears, lastYeare) = TimeHelper.GetStartOrEnd(dateTime, "lastYear");
  1570. int lessAll = 0; //所以课例
  1571. int lessLastdayCnt = 0; //昨天的课例
  1572. int lessDayCnt = 0; //今天的课例
  1573. int lessLastYearCnt = 0; //去年的课例
  1574. int lessYearCnt = 0; //今年的课例
  1575. int interAll = 0; //所有互动总数
  1576. int lastDayInterCnt = 0; // 昨天课例互动
  1577. int interCnt = 0; // 今天课例互动
  1578. int lastYearInterCnt = 0; // 去年课例互动
  1579. int yearInterCnt = 0; // 今年课例互动
  1580. int actAllCnt = 0; //所有活动
  1581. int lastActCnt = 0; //昨天活动
  1582. int actCnt = 0; //今天活动
  1583. int lastYearActCnt = 0; //去年活动
  1584. int yearActCnt = 0; //今年活动
  1585. List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
  1586. if (schoolIds.Count > 0)
  1587. {
  1588. string scSql = BICommonWay.ManyScSql("c.school", schoolIds);
  1589. string strSql = "SELECT value(count(c.id)) FROM c where c.pk='LessonRecord'";
  1590. //课例
  1591. lessAll = await CommonFind.GetSqlValueCount(cosmosClient, "School", $"{strSql} and {scSql}");
  1592. string lessLastdaySql = $"{strSql} and {scSql} and c.startTime >= { lastDays} and c.startTime <= {lastDaye} ";
  1593. lessLastdayCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lessLastdaySql);
  1594. string lessDaySql = $"{strSql} and {scSql} and c.startTime >= { days} and c.startTime <= {daye} ";
  1595. lessDayCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lessDaySql);
  1596. string lessLastYarSql = $"{strSql} and {scSql} and c.startTime >= { lastYears} and c.startTime <= {lastYeare} ";
  1597. lessLastYearCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lessLastYarSql);
  1598. string lessYearSql = $"{strSql} and {scSql} and c.startTime >= { years} and c.startTime <= {yeare} ";
  1599. lessYearCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lessYearSql);
  1600. //课例互动
  1601. string strInterSql = $"select value(sum(c.clientInteractionAverge)) from c where c.pk='LessonRecord' and {scSql}";
  1602. interAll = await CommonFind.GetSqlValueCount(cosmosClient, "School", strInterSql);
  1603. string lastdayInterSql = $"{strInterSql} and c.startTime >= { lastDays} and c.startTime <= {lastDaye} ";
  1604. lastDayInterCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lastdayInterSql);
  1605. string dayInterSql = $"{strInterSql} and c.startTime >= { days} and c.startTime <= {daye} ";
  1606. interCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", dayInterSql);
  1607. string lastYarInterSql = $"{strInterSql} and c.startTime >= { lastYears} and c.startTime <= {lastYeare} ";
  1608. lastYearInterCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", lastYarInterSql);
  1609. string yearInterSql = $"{strInterSql} and c.startTime >= { years} and c.startTime <= {yeare} ";
  1610. yearInterCnt = await CommonFind.GetSqlValueCount(cosmosClient, "School", yearInterSql);
  1611. //活动
  1612. string actAllSql = $" and {scSql} ";
  1613. actAllCnt = await ActivityWay.GetCnt(cosmosClient, actAllSql);
  1614. string lastActSql = $" and {scSql} and c.createTime >= {lastDays} and c.createTime <= {lastDaye}";
  1615. lastActCnt = await ActivityWay.GetCnt(cosmosClient, lastActSql);
  1616. string actSql = $" and {scSql} and c.createTime >= {days} and c.createTime <= {daye}";
  1617. actCnt = await ActivityWay.GetCnt(cosmosClient, actSql);
  1618. string lastYearActSql = $" and {scSql} and c.createTime >= {lastYears} and c.createTime <= {lastYeare}";
  1619. lastYearActCnt = await ActivityWay.GetCnt(cosmosClient, lastYearActSql);
  1620. string yearActSql = $" and {scSql} and c.createTime >= {years} and c.createTime <= {yeare}";
  1621. yearActCnt = await ActivityWay.GetCnt(cosmosClient, yearActSql);
  1622. }
  1623. return Ok(new { state = RespondCode.Ok, lessAll, lessLastdayCnt, lessDayCnt, lessLastYearCnt, lessYearCnt, interAll, lastDayInterCnt, interCnt, lastYearInterCnt, yearInterCnt, actAllCnt, lastActCnt, actCnt, lastYearActCnt, yearActCnt });
  1624. }
  1625. /// <summary>
  1626. /// 查询学校基础信息,和学校年级、科目数据统计
  1627. /// </summary>
  1628. /// <param name="jsonElement"></param>
  1629. /// <returns></returns>
  1630. [ProducesDefaultResponseType]
  1631. [HttpPost("get-ratio")]
  1632. public async Task<IActionResult> GetRatio(JsonElement jsonElement)
  1633. {
  1634. if (!jsonElement.TryGetProperty("schoolId", out JsonElement schoolId)) return BadRequest();
  1635. jsonElement.TryGetProperty("site", out JsonElement site);
  1636. var cosmosClient = _azureCosmos.GetCosmosClient();
  1637. if ($"{site}".Equals(BIConst.Global))
  1638. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  1639. AnSchool school = new(); //学校基础基础信息
  1640. int serial = 0; //学校软体数量
  1641. int service = 0; //学校服务数量
  1642. int hard = 0; //学校硬件数量
  1643. var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync($"{schoolId}", new PartitionKey("Base"));
  1644. if (response.Status == 200)
  1645. {
  1646. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  1647. school = json.ToObject<AnSchool>();
  1648. }
  1649. else return Ok(new { state = RespondCode.NotFound, msg = "未找到该学校" });
  1650. List<LessAnalyse> lessAnalyses = new();
  1651. await foreach (var lessItem in cosmosClient.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<LessAnalyse>(queryText: "select c.id,c.code,c.periodId,c.subjectId,c.grade from c", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord-{school.id}") }))
  1652. {
  1653. lessAnalyses.Add(lessItem);
  1654. }
  1655. List<(string name, string periodId, int count)> grades = LessonStatisWay.GetGradeCount(lessAnalyses);
  1656. var subs = lessAnalyses.GroupBy(x => x.subjectId).Where(y => !string.IsNullOrEmpty(y.Key)).Select(y => new { key = y.Key, count = y.ToList().Count }).ToList();
  1657. var gradeCnt = grades.Select(x => new { x.name, x.periodId,value = x.count });
  1658. var subCnt = subs.Select(x => new { name = x.key, value = x.count });
  1659. var responseProduct = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(school.id, new PartitionKey("ProductSum"));
  1660. if (responseProduct.Status == 200)
  1661. {
  1662. using var json = await JsonDocument.ParseAsync(responseProduct.ContentStream);
  1663. if (json.RootElement.TryGetProperty("serial", out JsonElement _serial) && !_serial.ValueKind.Equals(JsonValueKind.Null))
  1664. {
  1665. serial = _serial.ToObject<List<SchoolProductSumData>>().Count;//.Select(x => x.prodCode).ToList();
  1666. }
  1667. if (json.RootElement.TryGetProperty("service", out JsonElement _service) && !_service.ValueKind.Equals(JsonValueKind.Null))
  1668. {
  1669. service = _service.ToObject<List<SchoolProductSumData>>().Count;//.Select(x => x.prodCode).ToList();
  1670. }
  1671. if (json.RootElement.TryGetProperty("hard", out JsonElement _hard) && !_hard.ValueKind.Equals(JsonValueKind.Null))
  1672. {
  1673. hard = _hard.ToObject<List<SchoolProductSumDataHard>>().Count();//.Select(x => x.prodCode).ToList();
  1674. }
  1675. }
  1676. return Ok(new { state = RespondCode.Ok, school, gradeCnt, subCnt, serial, service, hard });
  1677. }
  1678. /// <summary>
  1679. /// 通过tmdID 账户查询学校专业和模组
  1680. /// </summary>
  1681. /// <param name="jsonElement"></param>
  1682. /// <returns></returns>
  1683. [ProducesDefaultResponseType]
  1684. [HttpPost("get-proded")]
  1685. public async Task<IActionResult> GetProdEd(JsonElement jsonElement)
  1686. {
  1687. if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return Ok(new { state = RespondCode.ParamsError, nsg = "参数错误" });
  1688. jsonElement.TryGetProperty("site", out JsonElement site);
  1689. var cosmosClient = _azureCosmos.GetCosmosClient();
  1690. if ($"{site}".Equals(BIConst.Global))
  1691. cosmosClient = _azureCosmos.GetCosmosClient(name: BIConst.Global);
  1692. List<string> schoolIds = await CommonFind.FindSchoolIds(cosmosClient, $"{tmdId}");
  1693. List<ScProdEd> scInfos = new();
  1694. List<string> products = new();
  1695. if (schoolIds.Count > 0)
  1696. {
  1697. string scInfoSql = $"select c.id,c.name,c.code,c.picture,c.type,c.size,c.scale from c ";
  1698. scInfos = await CommonFind.GetObject<ScProdEd>(cosmosClient, "School", scInfoSql, "Base", schoolIds);
  1699. if (schoolIds.Count > 0)
  1700. {
  1701. foreach (var scProd in scInfos)
  1702. {
  1703. var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(scProd.id, new PartitionKey("ProductSum"));
  1704. if (response.Status == 200)
  1705. {
  1706. using var json = await JsonDocument.ParseAsync(response.ContentStream);
  1707. if (json.RootElement.TryGetProperty("serial", out JsonElement serial) && !serial.ValueKind.Equals(JsonValueKind.Null))
  1708. {
  1709. List<string> serials = serial.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
  1710. scProd.serial = serials;
  1711. products.AddRange(serials);
  1712. }
  1713. if (json.RootElement.TryGetProperty("service", out JsonElement service) && !service.ValueKind.Equals(JsonValueKind.Null))
  1714. {
  1715. List<string> services = service.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
  1716. scProd.service = services;
  1717. products.AddRange(services);
  1718. }
  1719. if (json.RootElement.TryGetProperty("hard", out JsonElement hard) && !hard.ValueKind.Equals(JsonValueKind.Null))
  1720. {
  1721. List<string> hards = hard.ToObject<List<SchoolProductSumDataHard>>().Select(x => x.prodCode).ToList();
  1722. scProd.hard = hards;
  1723. products.AddRange(hards);
  1724. }
  1725. }
  1726. }
  1727. //scInfos.ForEach(async scProd =>
  1728. //{
  1729. // var response = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(scProd.id, new PartitionKey("ProductSum"));
  1730. // if (response.Status == 200)
  1731. // {
  1732. // using var json = await JsonDocument.ParseAsync(response.ContentStream);
  1733. // if (json.RootElement.TryGetProperty("serial", out JsonElement serial) && !serial.ValueKind.Equals(JsonValueKind.Null))
  1734. // {
  1735. // scProd.serial = serial.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
  1736. // }
  1737. // if (json.RootElement.TryGetProperty("service", out JsonElement service) && !service.ValueKind.Equals(JsonValueKind.Null))
  1738. // {
  1739. // scProd.service = service.ToObject<List<SchoolProductSumData>>().Select(x => x.prodCode).ToList();
  1740. // }
  1741. // if (json.RootElement.TryGetProperty("hard", out JsonElement hard) && !hard.ValueKind.Equals(JsonValueKind.Null))
  1742. // {
  1743. // scProd.hard = hard.ToObject<List<SchoolProductSumDataHard>>().Select(x => x.prodCode).ToList();
  1744. // }
  1745. // }
  1746. //});
  1747. }
  1748. }
  1749. var productAn = products.GroupBy(g => g).Select(s => new { key = s.Key, cnt = s.ToList().Count }).ToList();
  1750. return Ok(new { state = RespondCode.Ok, scInfos, productAn });
  1751. // var productAn = products.GroupBy(x => x).Select(y => new { key = y.Key, count = y.ToList().Count }).ToList();
  1752. }
  1753. #region 顾问学校统计返回值
  1754. public record ScRankCnt : SchoolBase
  1755. {
  1756. public int openCnt { get; set; }
  1757. public int lessCnt { get; set; }
  1758. public int interCnt { get; set; }
  1759. public int actCnt { get; set; }
  1760. }
  1761. public record SchoolBase
  1762. {
  1763. public string id { get; set; }
  1764. public string code { get; set; }
  1765. public string name { get; set; }
  1766. public string picture { get; set; }
  1767. }
  1768. #endregion
  1769. public record ApplySchool
  1770. {
  1771. public string id { get; set; }
  1772. public string code { get; set; }
  1773. public string name { get; set; }
  1774. public string picture { get; set; }
  1775. }
  1776. /// <summary>
  1777. /// 未加入区域的学校
  1778. /// </summary>
  1779. public record NotAreaSchool
  1780. {
  1781. public string id { get; set; }
  1782. public string name { get; set; }
  1783. public string schoolCode { get; set; }
  1784. public string picture { get; set; }
  1785. public List<string> period { get; set; }
  1786. public string province { get; set; }
  1787. public string city { get; set; }
  1788. public string dist { get; set; }
  1789. public string areaId { get; set; }
  1790. public string standard { get; set; }
  1791. public List<SchoolArea> areas { get; set; } = new List<SchoolArea>();
  1792. }
  1793. /// <summary>
  1794. /// 学校空间使用情况
  1795. /// </summary>
  1796. public record SchoolSpace
  1797. {
  1798. public string id { get; set; }
  1799. public string name { get; set; }
  1800. public Space space { get; set; }
  1801. }
  1802. /// <summary>
  1803. /// 空间
  1804. /// </summary>
  1805. public record Space
  1806. {
  1807. /// <summary>
  1808. /// 已使用空间
  1809. /// </summary>
  1810. public long useSize { get; set; }
  1811. /// <summary>
  1812. /// 分配教师空间
  1813. /// </summary>
  1814. public long tSize { get; set; }
  1815. /// <summary>
  1816. /// 空间类型
  1817. /// </summary>
  1818. public Dictionary<string, double?> catalogSize { get; set; }
  1819. }
  1820. public record DelSchoolRel
  1821. {
  1822. public string id { get; set; }
  1823. public string code { get; set; }
  1824. /// <summary>
  1825. /// 未删除的类型 1 学校 2教师 3学生
  1826. /// </summary>
  1827. public int type { get; set; }
  1828. public int status { get; set; }
  1829. }
  1830. }
  1831. }