SchoolController.cs 117 KB

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