OpenApiService.cs 126 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316
  1. using Azure;
  2. using Azure.Cosmos;
  3. using HTEXLib.COMM.Helpers;
  4. using Microsoft.AspNetCore.Http;
  5. using Microsoft.Azure.Cosmos.Table;
  6. using Microsoft.Azure.Functions.Worker.Http;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Net;
  12. using System.Net.Http;
  13. using System.Text;
  14. using System.Text.Json;
  15. using System.Threading.Tasks;
  16. using TEAMModelOS.Filter;
  17. using TEAMModelOS.SDK;
  18. using TEAMModelOS.SDK.DI;
  19. using TEAMModelOS.SDK.Extension;
  20. using TEAMModelOS.SDK.Models;
  21. using TEAMModelOS.SDK.Models.Table;
  22. using TEAMModelOS.SDK.Helper.Common.ReflectorExtensions;
  23. using TEAMModelOS.SDK.Context.Constant;
  24. using TEAMModelOS.SDK.Models.Dtos;
  25. using TEAMModelOS.SDK.Services;
  26. using Microsoft.Extensions.Configuration;
  27. using Azure.Messaging.ServiceBus;
  28. using TEAMModelOS.Models;
  29. using TEAMModelOS.SDK.Models.Service;
  30. using TEAMModelOS.SDK.Models.Cosmos.BI.BINormal;
  31. using TEAMModelOS.SDK.Models.Cosmos.Student;
  32. using Microsoft.OData.Edm;
  33. using System.IdentityModel.Tokens.Jwt;
  34. using TEAMModelOS.SDK.Models.Cosmos.OpenEntity;
  35. using Microsoft.OData.UriParser;
  36. using Azure.Core;
  37. using System.Security.Policy;
  38. using System.Net.Http.Json;
  39. using System.Drawing;
  40. using Microsoft.AspNetCore.DataProtection;
  41. using Newtonsoft.Json.Linq;
  42. using Microsoft.Extensions.Hosting;
  43. using Microsoft.AspNetCore.Hosting;
  44. using TEAMModelOS.Models.ShanDa;
  45. using System.Runtime.ConstrainedExecution;
  46. using DocumentFormat.OpenXml.Wordprocessing;
  47. namespace TEAMModelOS.SDK
  48. {
  49. public class OpenApiService
  50. {
  51. private static List<string> weekDays = new List<string> { "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN" };
  52. /// <summary>
  53. /// 第三方获取学校列表
  54. /// [ApiToken(Auth = "1000", Name = "合作商获取可访问的学校列表",TName ="",EName ="", RWN = "R", Limit = false)]
  55. /// </summary>
  56. /// <param name="_azureCosmos"></param>
  57. /// <param name="_dingDing"></param>
  58. /// <param name="json"></param>
  59. /// <returns></returns>
  60. public static async Task<ResponseData<List<BizSchool>>> GetSchools(AzureCosmosFactory _azureCosmos, DingDing _dingDing, string bizId)
  61. {
  62. try
  63. {
  64. List<BizSchool> schools = new();
  65. var response = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Normal").ReadItemStreamAsync(bizId, new PartitionKey("BizConfig"));
  66. if (response.Status == 200)
  67. {
  68. using var resJson = await JsonDocument.ParseAsync(response.ContentStream);
  69. Business bizConfig = resJson.ToObject<Business>();
  70. schools = bizConfig.schools;
  71. }
  72. else return new ResponseData<List<BizSchool>>() { code = RespondCode.NotFound, msg = "未找到该企业" };
  73. return new ResponseData<List<BizSchool>>() { code = RespondCode.Ok, msg = "成功", data = schools };
  74. }
  75. catch (Exception ex)
  76. {
  77. await _dingDing.SendBotMsg($"OpenApi,{Environment.GetEnvironmentVariable("Option:Location")} OpenApiService/GetSchools() 参数:bizId:{bizId} \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  78. return new ResponseData<List<BizSchool>>() { code = RespondCode.Error, msg = "服务端异常" };
  79. }
  80. }
  81. /// <summary>
  82. /// josn:
  83. /// {
  84. /// "roles":"",
  85. /// "scope":""
  86. /// "pageCount":"",
  87. /// "DESC":"",
  88. /// "ASC":"",
  89. /// "continuationToken":"",
  90. /// "school":"",
  91. /// "tmdid":""
  92. /// }
  93. /// </summary>
  94. /// <param name="azureCosmos"></param>
  95. /// <param name="dingDing"></param>
  96. /// <param name="id"></param>
  97. /// <param name="school"></param>
  98. /// <param name="json"></param>
  99. /// <returns></returns>
  100. /// <exception cref="NotImplementedException"></exception>
  101. public static async Task<ResponseData<dynamic>> GetLessonRecordCount(AzureCosmosFactory _azureCosmos, IConfiguration _configuration, AzureServiceBusFactory _serviceBus,
  102. Option _option, DingDing _dingDing, string id, string school, JsonElement json)
  103. {
  104. json.TryGetProperty("identity", out JsonElement _identity);
  105. string identity = "";
  106. if (!string.IsNullOrWhiteSpace($"{_identity}"))
  107. {
  108. identity = $"{_identity}";
  109. }
  110. json.TryGetProperty("managePage", out JsonElement _managePage);
  111. bool managePage = false;
  112. if (_managePage.ValueKind.Equals(JsonValueKind.True))
  113. {
  114. managePage = true;
  115. }
  116. StringBuilder sql = new StringBuilder();
  117. sql.Append("select c.id,c.groupIds,c.courseId from c ");
  118. Dictionary<string, object> dict = LessonService.GetLessonCond(json);
  119. AzureCosmosQuery cosmosDbQuery = SQLHelper.GetSQL(dict, sql);
  120. string tbname = "";
  121. string code = "";
  122. List<string> autoTch = new List<string>();
  123. string sqlPrivate = "";
  124. code = $"LessonRecord-{school}";
  125. tbname = "School";
  126. List<string> ids = new List<string>();
  127. //只查询某个老师的课例
  128. if (json.TryGetProperty("tmdid", out JsonElement tmdid) && !string.IsNullOrWhiteSpace($"{tmdid}"))
  129. {
  130. ids.Add($"{tmdid}");
  131. }
  132. else
  133. {
  134. string sqltch = "select distinct value(c.id) from c ";
  135. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School)
  136. .GetItemQueryIterator<string>(queryText: sqltch, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Teacher-{school}") }))
  137. {
  138. ids.Add(item);
  139. }
  140. }
  141. if (ids.Any())
  142. {
  143. string sqlTechbase = $"select distinct value(c.id) from c where c.id in ({string.Join(",", ids.Select(x => $"'{x}'"))}) and (array_contains(c.lessonShow,'student') or array_contains(c.lessonShow,'all')) ";
  144. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
  145. .GetItemQueryIterator<string>(queryText: sqlTechbase, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Base") }))
  146. {
  147. autoTch.Add(item);
  148. }
  149. }
  150. int count = 0;
  151. string sqlShow = "";
  152. if (identity.Equals("student"))
  153. {
  154. string autoSql = "";
  155. if (autoTch.Any())
  156. {
  157. autoSql = $" or c.tmdid in ({string.Join(",", autoTch.Select(x => $"'{x}'"))})";
  158. }
  159. sqlShow = $" and (array_contains(c.show,'student') or array_contains(c.show,'all') {autoSql} ) ";
  160. }
  161. string sql_status_managePage = " (c.status<>404 or IS_DEFINED(c.status) = false ) and ";
  162. if (managePage)
  163. {
  164. sql_status_managePage = "";
  165. }
  166. cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", $" where {sql_status_managePage} array_length(c.groupIds)>0 {sqlPrivate} {sqlShow} and ");
  167. List<LessonRecord> records = new List<LessonRecord>();
  168. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).GetItemQueryIterator<LessonRecord>(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
  169. {
  170. records.Add(item);
  171. }
  172. if (records.Any())
  173. {
  174. var groupIds = records.SelectMany(x => x.groupIds).ToHashSet();
  175. if (groupIds.Any())
  176. {
  177. var groups = await GroupListService.GetGroupListByListids(_azureCosmos.GetCosmosClient(), _dingDing, groupIds.ToList(), school, " c.id ");
  178. //获取已经被删除的名单。
  179. var idsExp = groupIds.Except(groups.Select(x => x.id));
  180. if (idsExp.Any())
  181. {
  182. foreach (var item in records)
  183. {
  184. int countRmv = item.groupIds.RemoveAll(x => idsExp.Contains(x));
  185. if (countRmv > 0)
  186. {
  187. try
  188. {
  189. LessonRecord record = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).ReadItemAsync<LessonRecord>(item.id, new PartitionKey(code));
  190. record.groupIds = item.groupIds;
  191. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).ReplaceItemAsync<LessonRecord>(record, item.id, new PartitionKey(code));
  192. }
  193. catch (CosmosException ex) when (ex.Status == 404)
  194. {
  195. continue;
  196. }
  197. }
  198. }
  199. }
  200. }
  201. }
  202. count = records.Count;
  203. ResponseData<dynamic> resDate = new ResponseData<dynamic>
  204. {
  205. code = RespondCode.Ok,
  206. msg = "成功",
  207. data = new
  208. {
  209. count = count,
  210. }
  211. };
  212. return resDate;
  213. }
  214. /// <summary>
  215. /// josn:
  216. /// {
  217. /// "roles":"",
  218. /// "scope":""
  219. /// "pageCount":"",
  220. /// "DESC":"",
  221. /// "ASC":"",
  222. /// "continuationToken":"",
  223. /// "school":"",
  224. /// "tmdid":""
  225. /// }
  226. /// </summary>
  227. /// <param name="azureCosmos"></param>
  228. /// <param name="dingDing"></param>
  229. /// <param name="id"></param>
  230. /// <param name="school"></param>
  231. /// <param name="json"></param>
  232. /// <returns></returns>
  233. /// <exception cref="NotImplementedException"></exception>
  234. public static async Task<ResponseData<dynamic>> GetLessonRecord(AzureCosmosFactory _azureCosmos, IConfiguration _configuration, AzureServiceBusFactory _serviceBus,
  235. Option _option, DingDing _dingDing, string id, string school, JsonElement json)
  236. {
  237. json.TryGetProperty("identity", out JsonElement _identity);
  238. string identity = "";
  239. if (!string.IsNullOrWhiteSpace($"{_identity}"))
  240. {
  241. identity = $"{_identity}";
  242. }
  243. json.TryGetProperty("managePage", out JsonElement _managePage);
  244. bool managePage = false;
  245. if (_managePage.ValueKind.Equals(JsonValueKind.True))
  246. {
  247. managePage = true;
  248. }
  249. StringBuilder sql = new StringBuilder();
  250. sql.Append("select value(c) from c ");
  251. int pageCount = 10;
  252. Dictionary<string, object> dict = LessonService.GetLessonCond(json);
  253. if (json.TryGetProperty("pageCount", out JsonElement _pageCount))
  254. {
  255. int.TryParse($"{_pageCount}", out int pcount);
  256. if (pcount > 0)
  257. {
  258. pageCount = pcount;
  259. }
  260. }
  261. if (json.TryGetProperty("DESC", out JsonElement desc))
  262. {
  263. dict.Add("@DESC", desc.ToString());
  264. }
  265. if (json.TryGetProperty("ASC", out JsonElement asc))
  266. {
  267. dict.Add("@ASC", asc.ToString());
  268. }
  269. string continuationToken = null;
  270. if (json.TryGetProperty("continuationToken", out JsonElement _continuationToken))
  271. {
  272. if (!string.IsNullOrEmpty($"{_continuationToken}"))
  273. {
  274. continuationToken = $"{_continuationToken}";
  275. }
  276. }
  277. AzureCosmosQuery cosmosDbQuery = SQLHelper.GetSQL(dict, sql);
  278. string tbname = "";
  279. string code = "";
  280. string sqlPrivate = "";
  281. List<string> autoTch = new List<string>();
  282. code = $"LessonRecord-{school}";
  283. tbname = "School";
  284. List<string> ids = new List<string>();
  285. //只查询某个老师的课例
  286. if (json.TryGetProperty("tmdid", out JsonElement tmdid) && !string.IsNullOrWhiteSpace($"{tmdid}"))
  287. {
  288. ids.Add($"{tmdid}");
  289. }
  290. else
  291. {
  292. string sqltch = "select distinct value(c.id) from c ";
  293. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School)
  294. .GetItemQueryIterator<string>(queryText: sqltch, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Teacher-{school}") }))
  295. {
  296. ids.Add(item);
  297. }
  298. }
  299. if (ids.Any())
  300. {
  301. string sqlTechbase = $"select distinct value(c.id) from c where c.id in ({string.Join(",", ids.Select(x => $"'{x}'"))}) and (array_contains(c.lessonShow,'student') or array_contains(c.lessonShow,'all')) ";
  302. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
  303. .GetItemQueryIterator<string>(queryText: sqlTechbase, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Base") }))
  304. {
  305. autoTch.Add(item);
  306. }
  307. }
  308. List<LessonRecord> lessonRecords = new List<LessonRecord>();
  309. try
  310. {
  311. string sqlShow = "";
  312. if (identity.Equals("student"))
  313. {
  314. string autoSql = "";
  315. if (autoTch.Any())
  316. {
  317. autoSql = $" or c.tmdid in ({string.Join(",", autoTch.Select(x => $"'{x}'"))})";
  318. }
  319. sqlShow = $" and (array_contains(c.show,'student') or array_contains(c.show,'all') {autoSql} ) ";
  320. }
  321. string sql_status_managePage = "(c.status<>404 or IS_DEFINED(c.status) = false ) and ";
  322. if (managePage)
  323. {
  324. sql_status_managePage = "";
  325. }
  326. cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", $" where {sql_status_managePage} array_length(c.groupIds)>0 {sqlPrivate} {sqlShow} and ");
  327. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname)
  328. .GetItemQueryStreamIterator(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, continuationToken: continuationToken,
  329. requestOptions: new QueryRequestOptions() { MaxItemCount = pageCount, PartitionKey = new PartitionKey(code) }))
  330. {
  331. using var jsonData = await JsonDocument.ParseAsync(item.ContentStream);
  332. if (jsonData.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  333. {
  334. foreach (var obj in jsonData.RootElement.GetProperty("Documents").EnumerateArray())
  335. {
  336. lessonRecords.Add(obj.ToObject<LessonRecord>());
  337. }
  338. continuationToken = item.GetContinuationToken();
  339. break;
  340. }
  341. }
  342. long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  343. //查询时处理已经过期的课例。防止ServiceBus未触发的。
  344. var expireRecords = lessonRecords.Where(x => x.expire > 0 && now > x.expire);
  345. try
  346. {
  347. foreach (var item in expireRecords)
  348. {
  349. //item.status = 404;
  350. //await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).ReplaceItemAsync(item, item.id, new PartitionKey(item.code));
  351. var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
  352. var messageChange = new ServiceBusMessage(new { delete_id = item.id, tmdid = item.tmdid, scope = item.scope, opt = "delete", school = item.school }.ToJsonString());
  353. messageChange.ApplicationProperties.Add("name", "LessonRecordEvent");
  354. await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageChange);
  355. }
  356. }
  357. catch (Exception ex)
  358. {
  359. await _dingDing.SendBotMsg($"{_option.Location},ServiceBus ,LessonRecordEvent 发送消息失败,检查是否配置正常。", GroupNames.成都开发測試群組);
  360. }
  361. var tmdids = lessonRecords.Select(x => x.tmdid).ToHashSet();
  362. if (tmdids != null && tmdids.Count > 0)
  363. {
  364. List<IdNameCode> codes = new List<IdNameCode>();
  365. string sqltmd = $"select c.id,c.name,c.picture from c where c.id in ({string.Join(",", tmdids.Select(x => $"'{x}'"))})";
  366. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<IdNameCode>(queryText: sqltmd, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
  367. {
  368. codes.Add(item);
  369. }
  370. if (codes.IsNotEmpty())
  371. {
  372. lessonRecords.ForEach(x =>
  373. {
  374. var tmd = codes.Find(z => z.id.Equals(x.tmdid));
  375. if (tmd != null)
  376. {
  377. x.tmdname = tmd.name;
  378. x.tmdpicture = tmd.picture;
  379. }
  380. });
  381. }
  382. }
  383. var groupIds = lessonRecords.SelectMany(x => x.groupIds);
  384. if (groupIds.Any())
  385. {
  386. List<GroupListDto> groupLists = await GroupListService.GetGroupListByListids(_azureCosmos.GetCosmosClient(), _dingDing, groupIds.ToList(), school);
  387. lessonRecords.ForEach(x =>
  388. {
  389. List<string> groupNmae = new List<string>();
  390. x.groupIds.ForEach(y =>
  391. {
  392. var dto = groupLists.Find(z => z.id.Equals(y));
  393. string name = dto != null ? dto.name : "-";
  394. groupNmae.Add(name);
  395. });
  396. x.groupNames = groupNmae;
  397. });
  398. }
  399. ResponseData<dynamic> resDate = new ResponseData<dynamic>
  400. {
  401. code = RespondCode.Ok,
  402. msg = "成功",
  403. data = new
  404. {
  405. currCount = lessonRecords.Count,
  406. continuationToken,
  407. lessonRecords = lessonRecords.Select(x => new { x.tmdid, x.tmdname, x.tmdpicture, x.name, x.school, x.startTime, x.duration, x.courseId, x.groupIds, x.periodId, x.subjectId, x.grade, x.id, x.category })
  408. }
  409. };
  410. return resDate;
  411. }
  412. catch (Exception)
  413. {
  414. continuationToken = null;
  415. ResponseData<dynamic> resDate = new ResponseData<dynamic> { code = RespondCode.Ok, msg = "成功", data = new { currCount = 0, continuationToken = continuationToken, lessonRecords } };
  416. return resDate;
  417. }
  418. }
  419. /// <summary>
  420. /// 学校基本信息
  421. /// //[ApiToken(Auth = "1001", Name = "学校基本信息",TName ="",EName ="", RWN = "R", Limit = false)]
  422. /// </summary>
  423. /// <param name="_azureCosmos"></param>
  424. /// <param name="_dingDing"></param>
  425. /// <param name="bizId"></param>
  426. /// <param name="schoolId"></param>
  427. /// <returns></returns>
  428. public static async Task<ResponseData<dynamic>> GetSchoolInfo(AzureCosmosFactory _azureCosmos, DingDing _dingDing, string bizId, string schoolId)
  429. {
  430. try
  431. {
  432. ResponseData<dynamic> resDate = new();
  433. School data = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(schoolId, new PartitionKey("Base"));
  434. List<dynamic> period = new();
  435. data.period.ForEach(x => { period.Add(new { x.subjects, x.grades, x.name, x.id, x.campusId, x.semesters }); });
  436. if (data != null)
  437. {
  438. resDate.code = RespondCode.Ok;
  439. resDate.msg = "成功";
  440. resDate.data = new { data.id, data.name, data.areaId, data.type, data.region, data.province, data.city, data.dist, data.campuses, period };
  441. }
  442. else
  443. {
  444. resDate.code = RespondCode.NotFound;
  445. resDate.msg = "未找到学校信息";
  446. }
  447. return resDate;
  448. }
  449. catch (Exception ex)
  450. {
  451. await _dingDing.SendBotMsg($"OpenApi,{Environment.GetEnvironmentVariable("Option:Location")} OpenApiService/GetSchoolInfo() 参数:bizId:{bizId},school:{schoolId} \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  452. return new ResponseData<dynamic>() { code = RespondCode.Error, msg = "服务端异常" };
  453. }
  454. }
  455. /// <summary>
  456. /// 名单列表信息 获取学校的行政班,教学班,教研组,研修名单
  457. /// [ApiToken(Auth = "1201", Name = "名单列表信息",TName ="",EName ="", RWN = "R", Limit = false)]
  458. /// </summary>
  459. /// <param name="_azureCosmos"></param>
  460. /// <param name="_dingDing"></param>
  461. /// <param name="bizId"></param>
  462. /// <param name="school"></param>
  463. /// <param name="json"></param>
  464. /// <returns></returns>
  465. public static async Task<ResponseData<List<OGroupList>>> GetGroupList(AzureCosmosFactory _azureCosmos, DingDing _dingDing, string bizId, string school, JsonElement json)
  466. {
  467. try
  468. {
  469. ResponseData<List<OGroupList>> resDate = new();
  470. List<OGroupList> groupLists = new();
  471. var client = _azureCosmos.GetCosmosClient();
  472. json.TryGetProperty("periodId", out JsonElement periodId);
  473. List<GroupListGrp> tempGroupLists = new();
  474. //包含,学校的行政班,教学班
  475. json.TryGetProperty("type", out JsonElement _type);
  476. List<string> types = null;
  477. if (_type.ValueKind.Equals(JsonValueKind.Array))
  478. {
  479. types = _type.ToObject<List<string>>();
  480. }
  481. else if (_type.ValueKind.Equals(JsonValueKind.String))
  482. {
  483. types = new List<string> { $"{types}" };
  484. }
  485. if (types.IsEmpty() || types.Contains("class"))
  486. {
  487. StringBuilder classsql = new StringBuilder($"SELECT c.id,c.name,c.periodId ,c.year FROM c ");
  488. if (!string.IsNullOrEmpty($"{periodId}"))
  489. {
  490. classsql.Append($" where c.periodId='{periodId}' ");
  491. }
  492. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<ClassInfo>(queryText: classsql.ToString(),
  493. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Class-{school}") }))
  494. {
  495. HashSet<string> groupNames = new HashSet<string>();
  496. string gpsql = $"SELECT distinct c.groupId,c.groupName FROM c where c.classId='{item.id}'and c.groupName <>null";
  497. await foreach (var gp in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: gpsql,
  498. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{school}") }))
  499. {
  500. groupNames.Add(gp.groupName);
  501. }
  502. ///行政班(学生搜寻classId动态返回)class
  503. GroupListGrp group = new GroupListGrp
  504. {
  505. id = item.id,
  506. code = $"GroupList-{school}",
  507. name = item.name,
  508. periodId = item.periodId,
  509. scope = "school",
  510. school = $"{school}",
  511. type = "class",
  512. year = item.year,
  513. expire = 0,
  514. groupName = groupNames
  515. };
  516. tempGroupLists.Add(group);
  517. }
  518. }
  519. if (types.IsEmpty() || types.Contains("teach"))
  520. {
  521. //教学班
  522. StringBuilder teachsql = new StringBuilder($" SELECT distinct value(c) FROM c where c.type='teach'");
  523. if (!string.IsNullOrEmpty($"{periodId}"))
  524. {
  525. teachsql.Append($" and c.periodId='{periodId}'");
  526. }
  527. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").
  528. GetItemQueryIterator<GroupList>(queryText: teachsql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"GroupList-{school}") }))
  529. {
  530. HashSet<string> groupName = item.members.Where(x => !string.IsNullOrEmpty(x.groupName)).Select(y => y.groupName).ToHashSet();
  531. tempGroupLists.Add(new GroupListGrp(item, groupName));
  532. }
  533. }
  534. if (types.IsEmpty() || types.Contains("research"))
  535. {
  536. //教研组
  537. StringBuilder researchsql = new StringBuilder($"SELECT distinct value(c) FROM c where c.type='research'");
  538. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").
  539. GetItemQueryIterator<GroupList>(queryText: researchsql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"GroupList-{school}") }))
  540. {
  541. HashSet<string> groupName = item.members.Where(x => !string.IsNullOrEmpty(x.groupName)).Select(y => y.groupName).ToHashSet();
  542. tempGroupLists.Add(new GroupListGrp(item, groupName));
  543. }
  544. }
  545. if (types.IsEmpty() || types.Contains("yxtrain"))
  546. {
  547. //研修名单
  548. StringBuilder yxtrainsql = new StringBuilder($"SELECT distinct value(c) FROM c where c.type='yxtrain'");
  549. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").
  550. GetItemQueryIterator<GroupList>(queryText: yxtrainsql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"GroupList-{school}") }))
  551. {
  552. HashSet<string> groupName = item.members.Where(x => !string.IsNullOrEmpty(x.groupName)).Select(y => y.groupName).ToHashSet();
  553. tempGroupLists.Add(new GroupListGrp(item, groupName));
  554. }
  555. }
  556. groupLists = tempGroupLists.Select(x => new OGroupList { id = x.id, name = x.name, type = x.type, periodId = x.periodId, school = x.school, scope = x.scope, year = x.year, expire = x.expire }).ToList();
  557. if (groupLists.Count > 0)
  558. {
  559. resDate.code = RespondCode.Ok;
  560. resDate.msg = "成功";
  561. resDate.data = groupLists;
  562. }
  563. else
  564. {
  565. resDate.code = RespondCode.NotFound;
  566. resDate.msg = "未找到学校信息";
  567. }
  568. return resDate;
  569. }
  570. catch (Exception ex)
  571. {
  572. await _dingDing.SendBotMsg($"OpenApi,{Environment.GetEnvironmentVariable("Option:Location")} OpenApiService/GetGroupList() 参数:bizId:{bizId},school:{school},json:{json.ToJsonString()} \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  573. return new ResponseData<List<OGroupList>>() { code = RespondCode.Error, msg = "服务端异常" };
  574. }
  575. }
  576. /// <summary>
  577. /// 名单成员信息,学生成员信息,包含(学生,成员)基本信息,分组等信息
  578. /// [ApiToken(Auth = "1202", Name = "名单成员信息",TName ="",EName ="", RWN = "R", Limit = false)]
  579. /// </summary>
  580. /// <param name="_azureCosmos"></param>
  581. /// <param name="_coreAPIHttpService"></param>
  582. /// <param name="_dingDing"></param>
  583. /// <param name="bizId"></param>
  584. /// <param name="school"></param>
  585. /// <param name="json"></param>
  586. /// <returns></returns>
  587. public static async Task<ResponseData<dynamic>> GetGroupMembers(AzureCosmosFactory _azureCosmos, CoreAPIHttpService _coreAPIHttpService, DingDing _dingDing, string bizId, string school, JsonElement json)
  588. {
  589. try
  590. {
  591. List<OGgroup> groups = new();
  592. var client = _azureCosmos.GetCosmosClient();
  593. if (!json.TryGetProperty("ids", out JsonElement ids)) return new ResponseData<dynamic>() { code = RespondCode.NotFound, msg = "参数错误" };
  594. List<string> listids = ids.ToObject<List<string>>();
  595. (List<RMember> members, List<RGroupList> tGroups) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, listids, $"{school}");
  596. groups = tGroups.Select(x => new OGgroup
  597. {
  598. name = x.name,
  599. no = x.no,
  600. periodId = x.periodId,
  601. school = x.school,
  602. type = x.type,
  603. year = x.year,
  604. expire = x.expire,
  605. tcount = x.tcount,
  606. scount = x.scount,
  607. leader = x.leader,
  608. members = x.members,
  609. id = x.id
  610. }).ToList();
  611. if (bizId.Equals("cc7e900c-4881-4fe9-9c64-abb1a1f95518") || bizId.Equals("8254bc86-aae9-4fef-9655-4fbda1bd39da"))
  612. {
  613. if (listids.Count == 1 && listids.First().Equals("TeacherAll") && !string.IsNullOrEmpty(school))
  614. {
  615. var keys = members.Select(x => x.id).ToHashSet();
  616. var content = new StringContent(keys.ToJsonString(), Encoding.UTF8, "application/json");
  617. string ujson = await _coreAPIHttpService.GetUserInfos(content);
  618. if (!string.IsNullOrWhiteSpace(ujson))
  619. {
  620. var coreUsers = ujson.ToObject<List<CoreUser>>();
  621. if (coreUsers.IsNotEmpty())
  622. {
  623. coreUsers.ForEach(z => {
  624. var mb = members.Find(x => x.id.Equals(z.id));
  625. if (mb != null)
  626. {
  627. mb.no = z.mobile;
  628. }
  629. });
  630. }
  631. }
  632. }
  633. }
  634. return new ResponseData<dynamic>() { code = RespondCode.Ok, msg = "成功", data = new { groups, members } };
  635. }
  636. catch (Exception ex)
  637. {
  638. await _dingDing.SendBotMsg($"OpenApi,{Environment.GetEnvironmentVariable("Option:Location")} OpenApiService/GetGroupMembers() 参数:bizId:{bizId},school:{school},json:{json.ToJsonString()} \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  639. return new ResponseData<dynamic>() { code = RespondCode.Error, msg = "服务端异常" };
  640. }
  641. }
  642. /// <summary>
  643. /// 获取课程列表信息
  644. /// [ApiToken(Auth = "1301", Name = "获取课程列表信息",TName ="",EName ="", RWN = "R", Limit = false)]
  645. /// </summary>
  646. /// <param name="_azureCosmos"></param>
  647. /// <param name="_dingDing"></param>
  648. /// <param name="bizId"></param>
  649. /// <param name="school"></param>
  650. /// <param name="json"></param>
  651. /// <returns></returns>
  652. public static async Task<ResponseData<dynamic>> GetCourseList(AzureCosmosFactory _azureCosmos, DingDing _dingDing, string bizId, string school, JsonElement json)
  653. {
  654. try
  655. {
  656. var client = _azureCosmos.GetCosmosClient();
  657. json.TryGetProperty("periodId", out JsonElement periodId);
  658. json.TryGetProperty("subjectId", out JsonElement subjectId);
  659. StringBuilder sql = new StringBuilder($"SELECT c.id,c.name,c.subject,c.period,c.scope,c.no,c.school FROM c where 1=1 ");
  660. if (!string.IsNullOrWhiteSpace($"{periodId}"))
  661. {
  662. sql.Append($" and c.period.id='{periodId}'");
  663. }
  664. if (!string.IsNullOrWhiteSpace($"{subjectId}"))
  665. {
  666. sql.Append($" and c.subject.id='{subjectId}'");
  667. }
  668. List<dynamic> courses = new List<dynamic>();
  669. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<dynamic>(queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Course-{school}") }))
  670. {
  671. courses.Add(item);
  672. }
  673. return new ResponseData<dynamic>() { code = RespondCode.Ok, msg = "成功", data = courses };
  674. }
  675. catch (Exception ex)
  676. {
  677. await _dingDing.SendBotMsg($"OpenApi,{Environment.GetEnvironmentVariable("Option:Location")} OpenApiService/GetCourseList() 参数:bizId:{bizId},school:{school},json:{json.ToJsonString()} \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  678. return new ResponseData<dynamic>() { code = RespondCode.Error, msg = "服务端异常" };
  679. }
  680. }
  681. /// <summary>
  682. /// 课程详细信息
  683. /// [ApiToken(Auth = "1302", Name = "课程详细信息",TName ="",EName ="", RWN = "R", Limit = false)]
  684. /// </summary>
  685. /// <param name="_azureCosmos"></param>
  686. /// <param name="_dingDing"></param>
  687. /// <param name="bizId"></param>
  688. /// <param name="school"></param>
  689. /// <param name="json"></param>
  690. /// <returns></returns>
  691. public static async Task<ResponseData<dynamic>> GetCourseInfo(AzureCosmosFactory _azureCosmos, DingDing _dingDing, string bizId, string school, JsonElement json)
  692. {
  693. try
  694. {
  695. json.TryGetProperty("courseId", out JsonElement courseId);
  696. Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{courseId}", new PartitionKey($"Course-{school}"));
  697. if (response.Status == 200)
  698. {
  699. JsonDocument document = JsonDocument.Parse(response.Content);
  700. Course course = document.RootElement.Deserialize<Course>();
  701. return new ResponseData<dynamic>() { code = RespondCode.Ok, msg = "成功", data = new { course.name, course.id, course.subject, course.period, course.scope, course.school, course.no, course.desc, course.schedule } };
  702. }
  703. else
  704. return new ResponseData<dynamic>() { code = RespondCode.NotFound, msg = "未找到相关课程" };
  705. }
  706. catch (Exception ex)
  707. {
  708. await _dingDing.SendBotMsg($"OpenApi,{Environment.GetEnvironmentVariable("Option:Location")} OpenApiService/GetCourseInfo() 参数:bizId:{bizId},school:{school},json:{json.ToJsonString()} \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  709. return new ResponseData<dynamic>() { code = RespondCode.Error, msg = "服务端异常" };
  710. }
  711. }
  712. /// <summary>
  713. /// 获取指定学段作息
  714. /// [ApiToken(Auth = "1303", Name = "获取指定学段作息",TName ="",EName ="", RWN = "R", Limit = false)]
  715. /// </summary>
  716. /// <param name="_azureCosmos"></param>
  717. /// <param name="_dingDing"></param>
  718. /// <param name="bizId"></param>
  719. /// <param name="school"></param>
  720. /// <param name="json"></param>
  721. /// <returns></returns>
  722. public static async Task<ResponseData<dynamic>> GetPaperExamCondition(AzureCosmosFactory _azureCosmos, DingDing _dingDing, string bizId, string school, JsonElement json)
  723. {
  724. try
  725. {
  726. json.TryGetProperty("periodId", out JsonElement _periodId);
  727. School data = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(school, new PartitionKey("Base"));
  728. var period = data.period.Find(x => x.id.Equals($"{_periodId}"));
  729. if (period != null)
  730. {
  731. return new ResponseData<dynamic>() { code = RespondCode.Ok, msg = "成功", data = new { period.subjects, period.timetable, period.grades, period.majors, weekDays } };
  732. }
  733. else
  734. return new ResponseData<dynamic>() { code = RespondCode.NotFound, msg = "未找到相关课程" };
  735. }
  736. catch (Exception ex)
  737. {
  738. await _dingDing.SendBotMsg($"OpenApi,{Environment.GetEnvironmentVariable("Option:Location")} OpenApiService/GetPaperExamCondition() 参数:bizId:{bizId},school:{school},json:{json.ToJsonString()} \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  739. return new ResponseData<dynamic>() { code = RespondCode.Error, msg = "服务端异常" };
  740. }
  741. }
  742. public static async Task<ResponseData<dynamic>> getCourseTechnology(IHttpClientFactory _httpClient, DingDing _dingDing, string bizId, string school, JsonElement json, IWebHostEnvironment _environment)
  743. {
  744. try
  745. {
  746. _httpClient.CreateClient().DefaultRequestHeaders.Add("ContentLength", "0");
  747. HttpContent httpContent = new StringContent(new { method = "statistic/data/" }.ToJsonString());
  748. /*Dictionary<string, object> data = new Dictionary<string, object>();
  749. data.Add("method", "statistic/data/");*/
  750. //data.Add("params", new { method = "statistic/data/"});
  751. //HttpResponseMessage responseMessage = await _httpClient.CreateClient().PostAsJsonAsync("http://116.204.72.199:81/statistic/data/", data);
  752. var response = await _httpClient.CreateClient().PostAsync("http://116.204.72.199:81/statistic/data/", httpContent);
  753. //获取配置文件内容
  754. string path = $"{_environment.ContentRootPath}/JsonFile/Core/field.json";
  755. StreamReader streamReader = new(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8);
  756. StringBuilder stringBuilder = new();
  757. string text;
  758. while ((text = streamReader.ReadLine()) != null)
  759. {
  760. stringBuilder.Append(text.ToString());
  761. }
  762. streamReader.Close();
  763. string input = stringBuilder.ToString();
  764. Field fields = input.ToObject<Field>();
  765. List<OCourseBase> courses = new();
  766. List<(string name, double T, double P, int attendCount, int mCount, int groups, long time,
  767. List<(string name, int count)> counts, List<(string name, double score)> ps,
  768. List<(string name, long time)> appTimes, List<(string name, string url, int duration, long time)> vd)> scores = new();
  769. //List<(string name, List<(string name, int count)> counts)> eveCounts = new();
  770. if (response.IsSuccessStatusCode)
  771. {
  772. string responseBody = response.Content.ReadAsStringAsync().Result;
  773. JObject jo = JObject.Parse(responseBody.ToString());
  774. JArray array = jo.Value<JArray>("base");
  775. foreach (var ne in array)
  776. {
  777. OCourseBase @base = new();
  778. var tname = ne["tmdname"].Value<string>();
  779. var cname = ne["courseName"].Value<string>();
  780. var attendCount = ne["attendCount"].Value<int>();
  781. var mCount = ne["mCount"].Value<int>();
  782. var time = ne["time"].Value<long>();
  783. var obj = ne["events"].ToObject<List<Events>>();
  784. var video = ne["videos"].ToObject<List<Videos>>();
  785. @base.tmdname = tname;
  786. @base.courseName = cname;
  787. @base.attendCount = attendCount;
  788. @base.mCount = mCount;
  789. @base.groups = new List<string>();
  790. @base.time = time;
  791. @base.eves = obj;
  792. @base.videos = video;
  793. //events.Add(obj);
  794. courses.Add(@base);
  795. }
  796. foreach (var eve in courses)
  797. {
  798. var countEve = eve.eves.GroupBy(x => x.@event).Select(y => new { name = y.Key, value = y.Sum(c => c.freq) });
  799. double scoreA = 0;
  800. if (countEve.Any())
  801. {
  802. scoreA += 20;
  803. }
  804. double scoreB = 0;
  805. int P1Count = 0;
  806. int P2Count = 0;
  807. int P3Count = 0;
  808. int P4Count = 0;
  809. int P5Count = 0;
  810. List<(string name, long time)> eveTimes = new();
  811. List<(string name, string url, int duration, long time)> videos = new();
  812. foreach (var v in eve.videos)
  813. {
  814. videos.Add((v.videoName, v.video, v.duration, v.startTime));
  815. }
  816. foreach (var apps in eve.eves)
  817. {
  818. var name = fields.fields.Where(x => x.field.Equals(apps.@event)).FirstOrDefault()?.desc;
  819. eveTimes.Add((name, apps.createTime));
  820. }
  821. List<(string name, int count)> eves = new();
  822. foreach (var per in countEve)
  823. {
  824. var name = fields.fields.Where(x => x.field.Equals(per.name)).FirstOrDefault()?.desc;
  825. eves.Add((name, per.value));
  826. foreach (var evePercent in fields.fields)
  827. {
  828. //计算T分
  829. if (per.name.Equals(evePercent.field))
  830. {
  831. if (evePercent.dimension.Equals("小组学习"))
  832. {
  833. P1Count++;
  834. }
  835. if (evePercent.dimension.Equals("全班互动"))
  836. {
  837. P2Count++;
  838. }
  839. if (evePercent.dimension.Equals("生本决策"))
  840. {
  841. P3Count++;
  842. }
  843. if (evePercent.dimension.Equals("全班测验"))
  844. {
  845. P4Count++;
  846. }
  847. if (evePercent.dimension.Equals("个人学习"))
  848. {
  849. P5Count++;
  850. }
  851. double bScore = 0;
  852. if (per.value == 1)
  853. {
  854. bScore += evePercent.percent * 0.9;
  855. }
  856. else if (per.value == 2)
  857. {
  858. bScore += evePercent.percent * 0.95;
  859. }
  860. else if (per.value >= 3)
  861. {
  862. bScore += evePercent.percent;
  863. }
  864. scoreB += bScore;
  865. }
  866. }
  867. }
  868. List<(string name, double score)> PScore = new();
  869. double P1Score = 0;
  870. if (P1Count == 1)
  871. {
  872. P1Score = 18 * 0.8;
  873. }
  874. else if (P1Count == 2)
  875. {
  876. P1Score = 18 * 0.9;
  877. }
  878. else if (P1Count >= 3)
  879. {
  880. P1Score = 18;
  881. }
  882. double P2Score = 0;
  883. if (P2Count == 1)
  884. {
  885. P2Score = 18 * 0.8;
  886. }
  887. else if (P2Count == 2)
  888. {
  889. P2Score = 18 * 0.9;
  890. }
  891. else if (P2Count >= 3)
  892. {
  893. P2Score = 18;
  894. }
  895. double P3Score = 0;
  896. if (P3Count == 1)
  897. {
  898. P3Score = 18 * 0.8;
  899. }
  900. else if (P3Count == 2)
  901. {
  902. P3Score = 18 * 0.9;
  903. }
  904. else if (P3Count >= 3)
  905. {
  906. P3Score = 18;
  907. }
  908. double P4Score = 0;
  909. if (P4Count == 1)
  910. {
  911. P4Score = 18 * 0.8;
  912. }
  913. else if (P3Count == 2)
  914. {
  915. P4Score = 18 * 0.9;
  916. }
  917. else if (P4Count >= 3)
  918. {
  919. P4Score = 18;
  920. }
  921. double P5Score = 0;
  922. if (P5Count == 1)
  923. {
  924. P5Score = 18 * 0.8;
  925. }
  926. else if (P5Count == 2)
  927. {
  928. P5Score = 18 * 0.9;
  929. }
  930. else if (P5Count >= 3)
  931. {
  932. P5Score = 18;
  933. }
  934. double P6Score = (P1Score + P2Score + P3Score + P4Score + P5Score) * 0.1;
  935. PScore.Add(("小组学习", P1Score));
  936. PScore.Add(("全班互动", P2Score));
  937. PScore.Add(("生本决策", P3Score));
  938. PScore.Add(("全班测验", P4Score));
  939. PScore.Add(("个人学习", P5Score));
  940. PScore.Add(("多元评价", P6Score));
  941. double P = P1Score + P2Score + P3Score + P4Score + P5Score + P6Score;
  942. double scoreC = (scoreA + scoreB) * 0.1;
  943. double scoreT = scoreA + scoreB + scoreC;
  944. scoreT = scoreT > 0 ? Math.Round(scoreT, 2) : 0;
  945. P = P > 0 ? Math.Round(P, 2) : 0;
  946. scores.Add((eve.courseName, scoreT, P, eve.attendCount, eve.mCount, eve.groups.Count, eve.time, eves, PScore, eveTimes, videos));
  947. //eveCounts.Add((eve.courseName, eves));
  948. }
  949. //var eve = courses.Select(c => c.eves).ToList();
  950. /*using JsonDocument document = JsonDocument.Parse(responseBody.ToString());
  951. if (document.RootElement.TryGetProperty("base", out JsonElement AccessTokenObj))
  952. {
  953. //AccessToken = AccessTokenObj.ToString();
  954. }*/
  955. }
  956. var courseScore = scores.Select(c => new
  957. {
  958. c.name,
  959. c.T,
  960. c.P,
  961. c.attendCount,
  962. c.mCount,
  963. c.groups,
  964. c.time,
  965. count = c.counts.Select(x => new { x.name, x.count }),
  966. pScore = c.ps.Select(x => new { x.name, x.score }),
  967. appTime = c.appTimes.Select(x => new { x.name, x.time }),
  968. videos = c.vd.Select(x => new { x.name, x.url, x.duration, x.time })
  969. });
  970. /*var courseCount = eveCounts.Select(c => new
  971. {
  972. c.name,
  973. count = c.counts.Select(x => new { x.name, x.count })
  974. });*/
  975. return new ResponseData<dynamic>() { code = RespondCode.Ok, msg = "成功", data = new { courseScore } };
  976. /*if (period != null)
  977. {
  978. return new ResponseData<dynamic>() { code = RespondCode.Ok, msg = "成功", data = new { period.subjects, period.timetable, period.grades, period.majors, weekDays } };
  979. }
  980. else
  981. return new ResponseData<dynamic>() { code = RespondCode.NotFound, msg = "未找到相关课程" };*/
  982. }
  983. catch (Exception ex)
  984. {
  985. await _dingDing.SendBotMsg($"OpenApi,{Environment.GetEnvironmentVariable("Option:Location")} OpenApiService/getCourseTechnology() 参数:bizId:{bizId},school:{school},json:{json.ToJsonString()} \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  986. return new ResponseData<dynamic>() { code = RespondCode.Error, msg = "服务端异常" };
  987. }
  988. }
  989. /// <summary>
  990. /// 物理教室列表
  991. /// [ApiToken(Auth = "1401", Name = "物理教室列表",TName ="",EName ="", RWN = "R", Limit = false)]
  992. /// </summary>
  993. /// <param name="_azureCosmos"></param>
  994. /// <param name="_dingDing"></param>
  995. /// <param name="bizId"></param>
  996. /// <param name="school"></param>
  997. /// <param name="json"></param>
  998. /// <returns></returns>
  999. public static async Task<ResponseData<List<ORoom>>> GetRoomList(AzureCosmosFactory _azureCosmos, DingDing _dingDing, string bizId, string school, JsonElement json)
  1000. {
  1001. try
  1002. {
  1003. var client = _azureCosmos.GetCosmosClient();
  1004. List<ORoom> dtRooms = new();
  1005. StringBuilder sql = new StringBuilder($"select value(c) from c where 1=1 ");
  1006. json.TryGetProperty("openType", out JsonElement openType);
  1007. json.TryGetProperty("no", out JsonElement no);
  1008. if (!string.IsNullOrWhiteSpace($"{openType}"))
  1009. {
  1010. sql.Append($" and c.openType='{openType}'");
  1011. }
  1012. if (!string.IsNullOrWhiteSpace($"{no}"))
  1013. {
  1014. sql.Append($" and c.no='{no}'");
  1015. }
  1016. List<Room> rooms = new List<Room>();
  1017. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<Room>(queryText: sql.ToString(),
  1018. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Room-{school}") }))
  1019. {
  1020. rooms.Add(item);
  1021. }
  1022. dtRooms = rooms.Select(s => new ORoom { id = s.id, name = s.name, x = s.x, y = s.y, openType = s.openType, style = s.style, area = s.area, address = s.address, school = school }).ToList();
  1023. if (dtRooms.Count > 0)
  1024. return new ResponseData<List<ORoom>>() { code = RespondCode.Ok, data = dtRooms };
  1025. else
  1026. return new ResponseData<List<ORoom>>() { code = RespondCode.NotFound, msg = "未找到该学校的物理教室" };
  1027. }
  1028. catch (Exception ex)
  1029. {
  1030. await _dingDing.SendBotMsg($"OpenApi,{Environment.GetEnvironmentVariable("Option:Location")} OpenApiService/GetRoomList() 参数:bizId:{bizId},school:{school},json:{json.ToJsonString()} \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  1031. return new ResponseData<List<ORoom>>() { code = RespondCode.Error, msg = "服务端异常" };
  1032. }
  1033. }
  1034. /// <summary>
  1035. /// 物理教室详细
  1036. /// [ApiToken(Auth = "1402", Name = "物理教室详细",TName ="",EName ="", RWN = "R", Limit = false)]
  1037. /// </summary>
  1038. /// <param name="_azureCosmos"></param>
  1039. /// <param name="_dingDing"></param>
  1040. /// <param name="bizId"></param>
  1041. /// <param name="school"></param>
  1042. /// <param name="json"></param>
  1043. /// <returns></returns>
  1044. public static async Task<ResponseData<dynamic>> GetRoomInfo(AzureCosmosFactory _azureCosmos, DingDing _dingDing, string bizId, string school, JsonElement json)
  1045. {
  1046. try
  1047. {
  1048. var client = _azureCosmos.GetCosmosClient();
  1049. if (!json.TryGetProperty("roomId", out JsonElement roomId)) return new ResponseData<dynamic>() { code = RespondCode.ParamsError, msg = "参数错误" };
  1050. Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{roomId}", new PartitionKey($"Room-{school}"));
  1051. if (response.Status == 200)
  1052. {
  1053. JsonDocument document = JsonDocument.Parse(response.Content);
  1054. Room tRoom = document.RootElement.Deserialize<Room>();
  1055. return new ResponseData<dynamic>() { code = RespondCode.Ok, msg = "成功", data = new { tRoom.id, tRoom.name, tRoom.x, tRoom.y, tRoom.openType, tRoom.style, tRoom.area, tRoom.address, school } };
  1056. }
  1057. else
  1058. return new ResponseData<dynamic>() { code = RespondCode.NotFound, msg = "未找到物理教室详情" };
  1059. }
  1060. catch (Exception ex)
  1061. {
  1062. await _dingDing.SendBotMsg($"OpenApi,{Environment.GetEnvironmentVariable("Option:Location")} OpenApiService/GetRoomInfo() 参数:bizId:{bizId},school:{school},json:{json.ToJsonString()} \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  1063. return new ResponseData<dynamic>() { code = RespondCode.Error, msg = "服务端异常" };
  1064. }
  1065. }
  1066. /// <summary>
  1067. /// 教师列表信息
  1068. /// [ApiToken(Auth = "1501", Name = "教师列表信息",TName ="",EName ="", RWN = "R", Limit = false)]
  1069. /// </summary>
  1070. /// <param name="_azureCosmos"></param>
  1071. /// <param name="_coreAPIHttpService"></param>
  1072. /// <param name="_dingDing"></param>
  1073. /// <param name="bizId"></param>
  1074. /// <param name="school"></param>
  1075. /// <param name="json"></param>
  1076. /// <returns></returns>
  1077. public static async Task<ResponseData<dynamic>> GetTeacherList(AzureCosmosFactory _azureCosmos, CoreAPIHttpService _coreAPIHttpService, DingDing _dingDing, string bizId, string school, JsonElement json)
  1078. {
  1079. try
  1080. {
  1081. var client = _azureCosmos.GetCosmosClient();
  1082. json.TryGetProperty("searchKey", out JsonElement _searchKey);
  1083. List<CoreUser> coreUsers = new(); List<CoreUser> unjoined = new();
  1084. IEnumerable<string> unexist = null;
  1085. StringBuilder sql = new("select c.id,c.name ,c.picture,c.job ,c.subjectIds,c.roles from c");
  1086. if (_searchKey.ValueKind.Equals(JsonValueKind.Array))
  1087. {
  1088. List<string> searchKey = _searchKey.ToObject<List<string>>();
  1089. if (searchKey.Any())
  1090. {
  1091. var keys = searchKey.Where(x => !string.IsNullOrWhiteSpace(x));
  1092. var content = new StringContent(keys.ToJsonString(), Encoding.UTF8, "application/json");
  1093. string ujson = await _coreAPIHttpService.GetUserInfos(content);
  1094. if (!string.IsNullOrWhiteSpace(ujson))
  1095. {
  1096. coreUsers = ujson.ToObject<List<CoreUser>>();
  1097. }
  1098. if (coreUsers.Any())
  1099. unexist = searchKey.Except(coreUsers.Select(x => x.searchKey));
  1100. else
  1101. return new ResponseData<dynamic>() { code = RespondCode.NotFound, msg = "没有找到对应的教师信息", data = _searchKey };
  1102. }
  1103. }
  1104. List<SchoolTeacher> teachers = new();
  1105. //string insql = "";
  1106. if (coreUsers.Any())
  1107. sql.Append($" where c.id in ({string.Join(",", coreUsers.Select(x => $"'{x.id}'"))}) ");
  1108. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<SchoolTeacher>
  1109. (queryText: sql.ToString(), requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Teacher-{school}") }))
  1110. {
  1111. teachers.Add(item);
  1112. }
  1113. if (coreUsers.Count > 0)
  1114. {
  1115. var teacherIds = coreUsers.Select(x => x.id).Except(teachers.Select(x => x.id));
  1116. unjoined = coreUsers.FindAll(x => teacherIds.Contains(x.id));
  1117. }
  1118. List<dynamic> tchs = new List<dynamic>();
  1119. teachers.Select(x => new { x.id, x.name, x.picture, x.job, x.subjectIds, x.roles }).ToList().ForEach(x =>
  1120. {
  1121. if (coreUsers.Count > 0)
  1122. {
  1123. var coreUser = coreUsers.Find(c => c.id.Equals(x.id));
  1124. if (coreUser != null)
  1125. {
  1126. tchs.Add(new { x.id, coreUser.name, coreUser.picture, x.job, x.subjectIds, x.roles, coreUser.searchKey, school });
  1127. }
  1128. }
  1129. else
  1130. tchs.Add(new { x.id, x.name, x.picture, x.job, x.subjectIds, x.roles, school });
  1131. });
  1132. return new ResponseData<dynamic>() { code = RespondCode.Ok, msg = "成功", data = new { tchs, unjoined = unjoined.Select(x => new { id = x.id, name = x.name, picture = x.picture, searchKey = x.searchKey }).ToList(), unexist } };
  1133. }
  1134. catch (Exception ex)
  1135. {
  1136. //await _dingDing.SendBotMsg($"OpenApi,{Environment.GetEnvironmentVariable("Option:Location")} OpenApiService/GetTeacherList() 参数:bizId:{bizId},school:{school},json:{json.ToJsonString()} \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  1137. return new ResponseData<dynamic>() { code = RespondCode.Error, msg = "服务端异常" };
  1138. }
  1139. }
  1140. /// <summary>
  1141. /// 教师执教的班级和课程
  1142. /// [ApiToken(Auth = "1502", Name = "教师详细信息",TName ="",EName ="", RWN = "R", Limit = false)]
  1143. /// </summary>
  1144. /// <param name="_azureCosmos"></param>
  1145. /// <param name="_dingDing"></param>
  1146. /// <param name="bizId"></param>
  1147. /// <param name="school"></param>
  1148. /// <param name="json"></param>
  1149. /// <returns></returns>
  1150. public static async Task<ResponseData<dynamic>> GetTeacherTeach(AzureCosmosFactory _azureCosmos, DingDing _dingDing, string bizId, string school, JsonElement json)
  1151. {
  1152. try
  1153. {
  1154. if (json.TryGetProperty("tmdid", out JsonElement _tmdid))
  1155. {
  1156. json.TryGetProperty("period", out JsonElement _period);
  1157. List<OCourse> courses = new List<OCourse>();
  1158. var query = $"SELECT distinct c.code,c.id,c.no,c.name,c.period,c.subject,c.scope ,c['desc'] ,c.creatorId , c.year ,s as schedule FROM c join s in c.schedule where s.teacherId='{_tmdid}' ";
  1159. HashSet<string> classIds = new HashSet<string>();
  1160. if (!string.IsNullOrWhiteSpace($"{_period}"))
  1161. {
  1162. query = $"{query} and c.period.id ='{_period}'";
  1163. }
  1164. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<OCourse>(queryText: query,
  1165. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Course-{school}") }))
  1166. {
  1167. if (!string.IsNullOrWhiteSpace(item.schedule?.stulist))
  1168. {
  1169. classIds.Add(item.schedule?.stulist);
  1170. }
  1171. if (!string.IsNullOrWhiteSpace(item.schedule?.classId))
  1172. {
  1173. classIds.Add(item.schedule?.classId);
  1174. }
  1175. courses.Add(item);
  1176. }
  1177. List<OGroupList> groupLists = new List<OGroupList>();
  1178. if (classIds.Any())
  1179. {
  1180. var tempGroupLists = await GroupListService.GetGroupListByListids(_azureCosmos.GetCosmosClient(), _dingDing, classIds.ToList(), school);
  1181. groupLists = tempGroupLists.Select(x => new OGroupList { id = x.id, name = x.name, type = x.type, periodId = x.periodId, school = x.school, scope = x.scope, year = x.year, expire = x.expire }).ToList();
  1182. }
  1183. var group = courses.GroupBy(x => x.id).Select(g => new { key = g.Key, list = g.ToList() });
  1184. List<Course> coursesR = new List<Course>();
  1185. group.ToList().ForEach(x =>
  1186. {
  1187. var first = x.list.First();
  1188. coursesR.Add(new Course
  1189. {
  1190. id = x.key,
  1191. name = first.name,
  1192. code = first.code,
  1193. no = first.no,
  1194. period = first.period,
  1195. subject = first.subject,
  1196. desc = first.desc,
  1197. creatorId = first.creatorId,
  1198. year = first.year,
  1199. schedule = x.list.Select(x => x.schedule).ToList()
  1200. });
  1201. });
  1202. return new ResponseData<dynamic>()
  1203. {
  1204. code = RespondCode.Ok,
  1205. data = new
  1206. {
  1207. courses = coursesR.Select(x => new
  1208. {
  1209. x.id,
  1210. school = school,
  1211. x.name,
  1212. x.no,
  1213. x.period,
  1214. x.subject,
  1215. x.desc,
  1216. x.creatorId,
  1217. x.year,
  1218. x.schedule
  1219. }),
  1220. groupLists
  1221. }
  1222. };
  1223. }
  1224. else
  1225. {
  1226. return new ResponseData<dynamic>() { code = RespondCode.ParamsError, msg = "参数错误" };
  1227. }
  1228. }
  1229. catch (Exception ex)
  1230. {
  1231. await _dingDing.SendBotMsg($"OpenApi,{Environment.GetEnvironmentVariable("Option:Location")} OpenApiService/GetTeacherTeach() 参数:bizId:{bizId},school:{school},json:{json.ToJsonString()} \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  1232. return new ResponseData<dynamic>() { code = RespondCode.Error, msg = "服务端异常" };
  1233. }
  1234. }
  1235. /// <summary>
  1236. /// 教师详细信息
  1237. /// [ApiToken(Auth = "1502", Name = "教师详细信息",TName ="",EName ="", RWN = "R", Limit = false)]
  1238. /// </summary>
  1239. /// <param name="_azureCosmos"></param>
  1240. /// <param name="_dingDing"></param>
  1241. /// <param name="bizId"></param>
  1242. /// <param name="school"></param>
  1243. /// <param name="json"></param>
  1244. /// <returns></returns>
  1245. public static async Task<ResponseData<dynamic>> GetTeacherInfo(AzureCosmosFactory _azureCosmos, DingDing _dingDing, string bizId, string school, JsonElement json)
  1246. {
  1247. try
  1248. {
  1249. var client = _azureCosmos.GetCosmosClient();
  1250. json.TryGetProperty("tmdid", out JsonElement _tmdid);
  1251. Response responseSchoolTch = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School")
  1252. .ReadItemStreamAsync($"{_tmdid}", new PartitionKey($"Teacher-{school}"));
  1253. Response responseTch = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher")
  1254. .ReadItemStreamAsync($"{_tmdid}", new PartitionKey($"Base"));
  1255. Teacher teacher = null;
  1256. if (responseTch.Status == 200)
  1257. {
  1258. teacher = JsonDocument.Parse(responseTch.Content).RootElement.Deserialize<Teacher>();
  1259. }
  1260. else
  1261. return new ResponseData<dynamic> { code = RespondCode.NotFound, msg = "账号未创建" };
  1262. if (responseSchoolTch.Status == 200 && teacher != null)
  1263. {
  1264. SchoolTeacher schoolTeacher = JsonDocument.Parse(responseSchoolTch.Content).RootElement.Deserialize<SchoolTeacher>();
  1265. return new ResponseData<dynamic> { code = RespondCode.Ok, msg = "成功", data = new { teacher.id, teacher.name, teacher.picture, schoolTeacher.job, schoolTeacher.status, schoolTeacher.roles, schoolTeacher.subjectIds, school = teacher.schools?.Find(x => x.schoolId.Equals(school)) } };
  1266. }
  1267. else
  1268. return new ResponseData<dynamic> { code = RespondCode.NotFound, msg = "教师未就职该学校" };
  1269. }
  1270. catch (Exception ex)
  1271. {
  1272. await _dingDing.SendBotMsg($"OpenApi,{Environment.GetEnvironmentVariable("Option:Location")} OpenApiService/GetTeacherInfo() 参数:bizId:{bizId},school:{school},json:{json.ToJsonString()} \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  1273. return new ResponseData<dynamic>() { code = RespondCode.Error, msg = "服务端异常" };
  1274. }
  1275. }
  1276. /// <summary>
  1277. /// 教师批量导入,并加入学校。可以导入学科,但需要填写学段id
  1278. /// [ApiToken(Auth = "1503", Name = "教师批量导入",TName ="",EName ="", RWN = "R", Limit = false)]
  1279. /// </summary>
  1280. /// <param name="_azureCosmos"></param>
  1281. /// <param name="_coreAPIHttpService"></param>
  1282. /// <param name="_dingDing"></param>
  1283. /// <param name="bizId"></param>
  1284. /// <param name="school"></param>
  1285. /// <param name="json"></param>
  1286. /// <returns></returns>
  1287. public static async Task<ResponseData<List<OTeachers>>> GetTeacherInfo(AzureCosmosFactory _azureCosmos, CoreAPIHttpService _coreAPIHttpService, DingDing _dingDing, string bizId, string school, ImportTechDto json)
  1288. {
  1289. try
  1290. {
  1291. //如果需要同时导入学科,则需要填写学段
  1292. List<ImportTech> impTeachers = json.teachers;
  1293. List<string> searchKey = impTeachers.Select(x => x.id).ToList();
  1294. string ujson = null;
  1295. var keys = searchKey.Where(x => !string.IsNullOrWhiteSpace(x));
  1296. if (keys.Any())
  1297. {
  1298. var content = new StringContent(keys.ToJsonString(), Encoding.UTF8, "application/json");
  1299. ujson = await _coreAPIHttpService.GetUserInfos(content);
  1300. }
  1301. List<CoreUser> coreUsers = new List<CoreUser>();
  1302. if (!string.IsNullOrWhiteSpace(ujson))
  1303. {
  1304. coreUsers = ujson.ToObject<List<CoreUser>>();
  1305. }
  1306. IEnumerable<string> unexist = new List<string>();
  1307. if (coreUsers.Any())
  1308. {
  1309. unexist = searchKey.Except(coreUsers.Select(x => x.id));
  1310. }
  1311. else
  1312. {
  1313. return new ResponseData<List<OTeachers>>() { code = RespondCode.NotFound, msg = "没有找到对应的教师信息" };
  1314. }
  1315. var exist = coreUsers.Select(x => x.id);
  1316. //注册了账号的教师
  1317. impTeachers = impTeachers.Where(x => exist.Contains(x.id)).ToList();
  1318. List<Teacher> teachersList = new List<Teacher>();
  1319. List<SchoolTeacher> schoolTeachers = new List<SchoolTeacher>();
  1320. string sql = $"select value(c) from c where c.id in ({string.Join(",", impTeachers.Select(x => $"'{x.id}'"))})";
  1321. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
  1322. .GetItemQueryIterator<Teacher>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
  1323. {
  1324. teachersList.Add(item);
  1325. }
  1326. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School)
  1327. .GetItemQueryIterator<SchoolTeacher>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Teacher-{school}") }))
  1328. {
  1329. schoolTeachers.Add(item);
  1330. }
  1331. long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  1332. School data = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(school, new PartitionKey("Base"));
  1333. //学校学科发生变化。
  1334. List<SchoolTeacher> schoolTeachersAdd = new List<SchoolTeacher>();
  1335. bool baseChange = false;
  1336. foreach (var item in impTeachers)
  1337. {
  1338. var teacher = teachersList.Find(x => x.id.Equals(item.id));
  1339. var coreUser = coreUsers.Find(x => x.id.Equals(item.id));
  1340. if (teacher != null)
  1341. {
  1342. var sch = teacher.schools?.Find(x => x.schoolId.Equals(school));
  1343. if (sch == null)
  1344. {
  1345. if (teacher.schools.IsNotEmpty())
  1346. {
  1347. teacher.schools.Add(new Teacher.TeacherSchool { schoolId = school, name = data.name, status = "invite", time = now, picture = data.picture, areaId = data.areaId });
  1348. }
  1349. else
  1350. {
  1351. teacher.defaultSchool = school;
  1352. teacher.size = teacher.size + 1;
  1353. teacher.schools = new List<Teacher.TeacherSchool> { new Teacher.TeacherSchool { schoolId = school, name = data.name, status = "invite", time = now, picture = data.picture, areaId = data.areaId } };
  1354. }
  1355. }
  1356. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync(teacher, teacher.id, new PartitionKey("Base"));
  1357. }
  1358. else
  1359. {
  1360. teacher = new Teacher
  1361. {
  1362. createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
  1363. id = coreUser.id,
  1364. name = coreUser.name,
  1365. picture = coreUser.picture,
  1366. defaultSchool = school,
  1367. size = 2,
  1368. code = "Base",
  1369. pk = "Base",
  1370. schools = new List<Teacher.TeacherSchool> { new Teacher.TeacherSchool { schoolId = school, name = data.name, status = "invite", time = now, picture = data.picture, areaId = data.areaId } }
  1371. };
  1372. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).CreateItemAsync(teacher, new PartitionKey("Base"));
  1373. }
  1374. var schoolTeacher = schoolTeachers.Find(x => x.id.Equals(item.id));
  1375. //处理导入的学科
  1376. List<string> subjectIds = new List<string>();
  1377. if (item.subjects.IsNotEmpty() && !string.IsNullOrWhiteSpace(item.periodId))
  1378. {
  1379. item.subjects.ForEach(s =>
  1380. {
  1381. //同名学科
  1382. var subject = data.period.Find(x => x.id.Equals(item.periodId))?.subjects?.Find(x => x.id.Equals(s.id));
  1383. if (subject == null)
  1384. {
  1385. subject = data.period.Find(x => x.id.Equals(item.periodId))?.subjects?.Find(x => x.name.Equals(s.name));
  1386. }
  1387. else
  1388. {
  1389. subjectIds.Add(subject.id);
  1390. }
  1391. if (subject == null)
  1392. {
  1393. var period = data.period.Find(x => x.id.Equals(item.periodId));
  1394. if (period != null)
  1395. {
  1396. period.subjects.Add(new Subject { id = s.id, name = s.name, type = 2 });
  1397. subjectIds.Add(s.id);
  1398. baseChange = true;
  1399. }
  1400. }
  1401. });
  1402. }
  1403. if (schoolTeacher == null)
  1404. {
  1405. schoolTeacher = new SchoolTeacher
  1406. {
  1407. id = item.id,
  1408. name = coreUser.name,
  1409. picture = coreUser.picture,
  1410. job = item.job,
  1411. subjectIds = subjectIds,
  1412. roles = new List<string> { "teacher" },
  1413. permissions = new List<string> { "content-read", "exercise-read", "knowledge-read", "syllabus-read" },
  1414. status = "invite",
  1415. code = $"Teacher-{school}",
  1416. pk = "Teacher",
  1417. createTime = now,
  1418. };
  1419. schoolTeachersAdd.Add(schoolTeacher);
  1420. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).CreateItemAsync(schoolTeacher, new PartitionKey(schoolTeacher.code));
  1421. }
  1422. else
  1423. {
  1424. if (subjectIds.IsNotEmpty())
  1425. {
  1426. subjectIds.ForEach(x =>
  1427. {
  1428. if (!schoolTeacher.subjectIds.Contains(x))
  1429. {
  1430. schoolTeacher.subjectIds.Add(x);
  1431. }
  1432. });
  1433. }
  1434. schoolTeacher.job = string.IsNullOrWhiteSpace(item.job) ? schoolTeacher.job : item.job;
  1435. schoolTeachersAdd.Add(schoolTeacher);
  1436. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync(schoolTeacher, schoolTeacher.id, new PartitionKey(schoolTeacher.code));
  1437. }
  1438. }
  1439. if (baseChange)
  1440. {
  1441. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync(data, data.id, new PartitionKey("Base"));
  1442. }
  1443. return new ResponseData<List<OTeachers>>() { code = RespondCode.Ok, msg = "成功", data = schoolTeachersAdd.Select(x => new OTeachers { id = x.id, name = x.name, picture = x.picture, job = x.job, subjectIds = x.subjectIds, roles = x.roles, school = school }).ToList() };
  1444. //return schoolTeachersAdd.Select(x => new OTeachers { id = x.id, name = x.name, picture = x.picture, job = x.job, subjectIds = x.subjectIds, roles = x.roles, school = school }).ToList();
  1445. }
  1446. catch (Exception ex)
  1447. {
  1448. await _dingDing.SendBotMsg($"OpenApi,{Environment.GetEnvironmentVariable("Option:Location")} OpenApiService/GetTeacherInfo() 参数:bizId:{bizId},school:{school},json:{json} \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  1449. return new ResponseData<List<OTeachers>>() { code = RespondCode.Error, msg = "服务端异常" };
  1450. }
  1451. }
  1452. /// <summary>
  1453. /// 查找课纲
  1454. /// [ApiToken(Auth = "1601", Name = "查询课纲",TName ="",EName ="", RWN = "R", Limit = false)]
  1455. /// </summary>
  1456. /// <param name="_azureCosmos"></param>
  1457. /// <param name="json"></param>
  1458. /// <returns></returns>
  1459. public static async Task<ResponseData<List<OSyllabusTreeNode>>> GetSyllabus(AzureCosmosFactory _azureCosmos, DingDing _dingDing, string bizId, string school, JsonElement json)
  1460. {
  1461. try
  1462. {
  1463. if (!json.TryGetProperty("volumeId", out JsonElement volumeId)) return new ResponseData<List<OSyllabusTreeNode>>() { code = RespondCode.ParamsError, msg = "参数错误" };
  1464. //if (!json.TryGetProperty("volumeCode", out JsonElement volumeCode)) return new ResponseData<List<OSyllabusTreeNode>>() { code = RespondCode.ParamsError, msg = "参数错误" };
  1465. if (!json.TryGetProperty("scope", out JsonElement scope)) return new ResponseData<List<OSyllabusTreeNode>>() { code = RespondCode.ParamsError, msg = "参数错误" };
  1466. var client = _azureCosmos.GetCosmosClient();
  1467. OVolume volume = null;
  1468. List<OSyllabusTreeNode> treeNodes = new();
  1469. List<OSyllabusTreeNode> redt = new();
  1470. if ($"{scope}".Equals("school"))
  1471. {
  1472. List<OSyllabus> delSyllabus = new();
  1473. volume = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<OVolume>($"{volumeId}", new PartitionKey($"Volume-{school}"));
  1474. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<OSyllabus>(queryText: $"select value(c) from c where c.volumeId='{volumeId}'",
  1475. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Syllabus-{volume.school}") }))
  1476. {
  1477. if (item.children.IsEmpty())
  1478. {
  1479. delSyllabus.Add(item);
  1480. }
  1481. else
  1482. {
  1483. List<OSyllabusTree> trees = SyllabusService.OListToTree(item.children);
  1484. OSyllabusTreeNode otree = new() { id = item.id, scope = item.scope, trees = trees, volumeId = item.volumeId, codeval = volume.school };
  1485. treeNodes.Add(otree);
  1486. }
  1487. }
  1488. if (delSyllabus.IsNotEmpty())
  1489. {
  1490. await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemsAsync<OSyllabus>(delSyllabus.Select(x => x.id).ToList(), $"Syllabus-{volume.school}");
  1491. }
  1492. }
  1493. else
  1494. return new ResponseData<List<OSyllabusTreeNode>>() { code = RespondCode.ParamsError, msg = "参数错误" };
  1495. ResponseData<List<OSyllabusTreeNode>> responseData = new();
  1496. //对课纲树形结构排序
  1497. if (volume.syllabusIds.IsNotEmpty())
  1498. {
  1499. volume.syllabusIds.ForEach(x =>
  1500. {
  1501. for (int index = 0; index < treeNodes.Count; index++)
  1502. {
  1503. if (treeNodes[index].id == x)
  1504. {
  1505. redt.Add(treeNodes[index]);
  1506. treeNodes.RemoveAt(index);
  1507. }
  1508. }
  1509. });
  1510. redt.AddRange(treeNodes);
  1511. responseData = new ResponseData<List<OSyllabusTreeNode>>() { code = RespondCode.Ok, msg = "成功", data = redt };
  1512. }
  1513. else
  1514. {
  1515. responseData = new ResponseData<List<OSyllabusTreeNode>>() { code = RespondCode.Ok, msg = "成功", data = treeNodes };
  1516. }
  1517. return responseData;
  1518. }
  1519. catch (Exception ex)
  1520. {
  1521. await _dingDing.SendBotMsg($"OpenApi,{Environment.GetEnvironmentVariable("Option:Location")} OpenApiService/GetSyllabus() 参数:bizId:{bizId},school:{school},参数json:{json.ToJsonString()} \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  1522. return new ResponseData<List<OSyllabusTreeNode>>() { code = RespondCode.Error, msg = "服务端异常" };
  1523. }
  1524. }
  1525. /// <summary>
  1526. /// 查询册别清单
  1527. /// [ApiToken(Auth = "1602", Name = "查询册别",TName ="",EName ="", RWN = "R", Limit = false)]
  1528. /// </summary>
  1529. /// <param name="_azureCosmos"></param>
  1530. /// <param name="_dingDing"></param>
  1531. /// <param name="json"></param>
  1532. /// <returns></returns>
  1533. public static async Task<ResponseData<List<OVolume>>> GetVolumes(AzureCosmosFactory _azureCosmos, DingDing _dingDing, string bizId, string school, JsonElement json)
  1534. {
  1535. try
  1536. {
  1537. ResponseData<List<OVolume>> responseData = new();
  1538. List<OVolume> ovolumes = new List<OVolume>();
  1539. json.TryGetProperty("periodId", out JsonElement periodCode);
  1540. json.TryGetProperty("subjectId", out JsonElement subjectCode);
  1541. json.TryGetProperty("status", out JsonElement status);
  1542. json.TryGetProperty("scope", out JsonElement scope);
  1543. if (scope.GetString().Equals("school"))
  1544. {
  1545. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<OVolume>(queryText: $"select value(c) from c where c.status = {status} and c.periodId = '{periodCode}' and c.subjectId = '{subjectCode}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Volume-{school}") }))
  1546. {
  1547. ovolumes.Add(item);
  1548. }
  1549. }
  1550. else { return new ResponseData<List<OVolume>>() { code = RespondCode.ParamsError, msg = "参数错误" }; };
  1551. if (ovolumes.Count > 0)
  1552. {
  1553. responseData = new ResponseData<List<OVolume>>() { code = RespondCode.Ok, msg = "成功", data = ovolumes };
  1554. }
  1555. else
  1556. responseData = new ResponseData<List<OVolume>>() { code = RespondCode.NotFound, msg = "未找到参数相关的数据" };
  1557. return responseData;
  1558. }
  1559. catch (Exception ex)
  1560. {
  1561. await _dingDing.SendBotMsg($"OpenApi,{Environment.GetEnvironmentVariable("Option:Location")} OpenApiService/GetVolumes() 参数:bizId:{bizId},school:{school},参数json:{json.ToJsonString()} \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  1562. return new ResponseData<List<OVolume>>() { code = RespondCode.Error, msg = "服务端异常" };
  1563. }
  1564. }
  1565. /// <summary>
  1566. /// 查询知识
  1567. /// [ApiToken(Auth = "1701", Name = "查询知识点",TName ="",EName ="", RWN = "R", Limit = false)]
  1568. /// </summary>
  1569. /// <param name="_azureCosmos"></param>
  1570. /// <param name="_dingDing"></param>
  1571. /// <param name="json"></param>
  1572. /// <returns></returns>
  1573. public static async Task<ResponseData<dynamic>> GetKnowledges(AzureCosmosFactory _azureCosmos, DingDing _dingDing, string bizId, string school, JsonElement json)
  1574. {
  1575. try
  1576. {
  1577. ResponseData<dynamic> responseData = new();
  1578. var client = _azureCosmos.GetCosmosClient();
  1579. json.TryGetProperty("periodId", out JsonElement periodId);
  1580. if (!json.TryGetProperty("subjectId", out JsonElement subjectId)) return new ResponseData<dynamic>() { code = RespondCode.ParamsError, msg = "参数错误" };
  1581. //if (!json.TryGetProperty("school_code", out JsonElement school_code)) return new ResponseData<List<Knowledge>>() { code = RespondCode.ParamsError, msg = "参数错误" };
  1582. string code = $"Knowledge-{school}-{subjectId}";
  1583. StringBuilder sql = new($"select value(c) from c");
  1584. if (periodId.ValueKind.Equals(JsonValueKind.String))
  1585. {
  1586. sql.Append($" where c.periodId = '{periodId}'");
  1587. }
  1588. List<dynamic> knowledges = new();
  1589. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<Knowledge>(queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
  1590. {
  1591. knowledges.Add(new { item.periodId, item.subjectId, item.points, item.blocks, item.id });
  1592. }
  1593. if (knowledges.Any())
  1594. {
  1595. var data = knowledges.Select(x => new { });
  1596. responseData = new() { code = RespondCode.Ok, msg = "成功", data = knowledges };
  1597. }
  1598. else
  1599. {
  1600. responseData = new() { code = RespondCode.NotFound, msg = "未找到相关" };
  1601. }
  1602. return responseData;
  1603. }
  1604. catch (Exception ex)
  1605. {
  1606. await _dingDing.SendBotMsg($"OpenApi,{Environment.GetEnvironmentVariable("Option:Location")} OpenApiService/GetKnowledges() 参数:bizId:{bizId},school:{school},参数json:{json.ToJsonString()} \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  1607. return new ResponseData<dynamic>() { code = RespondCode.Error, msg = "服务端异常" };
  1608. }
  1609. }
  1610. /// <summary>
  1611. /// 设置学生全面教育画像
  1612. ///[ApiToken(Auth = "1901", Name = "设置学生全面教育画像", TName = "設置學生全面教育畫像", EName = "Set up students overall education portrait", RWN = "W", Limit = false)]
  1613. /// </summary>
  1614. /// <param name="_azureCosmos"></param>
  1615. /// <param name="_dingDing"></param>
  1616. /// <param name="json"></param>
  1617. /// <returns></returns>
  1618. public static async Task<ResponseData<dynamic>> UpsertStudentPortrait(AzureCosmosFactory _azureCosmos, DingDing _dingDing,AzureRedisFactory _azureRedis , JsonElement json,string school=null)
  1619. {
  1620. try
  1621. {
  1622. ResponseData<dynamic> responseData = new();
  1623. var client = _azureCosmos.GetCosmosClient();
  1624. if (!json.TryGetProperty("schoolCode", out JsonElement schoolCode))
  1625. {
  1626. return responseData = new() { code = RespondCode.ParamsError, msg = "schoolCode为空" };
  1627. }
  1628. #if !DEBUG
  1629. if (!string.IsNullOrWhiteSpace(school) && !school.Equals($"{schoolCode}", StringComparison.OrdinalIgnoreCase)) {
  1630. return responseData = new() { code = RespondCode.ParamsError, msg = "授权学校与参数schoolCode不匹配" };
  1631. }
  1632. #endif
  1633. if (!json.TryGetProperty("periodId", out JsonElement periodId))
  1634. {
  1635. return responseData = new() { code = RespondCode.ParamsError, msg = "periodId为空" };
  1636. }
  1637. if (!json.TryGetProperty("subjectId", out JsonElement subjectId))
  1638. {
  1639. return responseData = new() { code = RespondCode.ParamsError, msg = "subjectId为空" };
  1640. }
  1641. if (!json.TryGetProperty("students", out JsonElement _students) && !_students.ValueKind.Equals(JsonValueKind.Array))
  1642. {
  1643. return responseData = new() { code = RespondCode.ParamsError, msg = "students为空或格式错误" };
  1644. }
  1645. if (!$"{subjectId}".Equals("subject_sport") && !$"{subjectId}".Equals("subject_virtue") && !$"{subjectId}".Equals("subject_labour")
  1646. && !$"{subjectId}".Equals("subject_intelligence")
  1647. && !$"{subjectId}".Equals("subject_art"))
  1648. {
  1649. return responseData = new() { code = RespondCode.ParamsError, msg = "当前subjectId未开放画像业务" };
  1650. }
  1651. School schoolBase = await client.GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>($"{schoolCode}", new PartitionKey("Base"));
  1652. List<PortraitStudent> students = _students.ToObject<List<PortraitStudent>>();
  1653. List<(Student studentBase, PortraitStudent portrait)> studentsBases = new List<(Student, PortraitStudent)>();
  1654. //学生信息不匹配的
  1655. List<PortraitStudent> unmatchStuInfo = new List<PortraitStudent>();
  1656. //学期不匹配的
  1657. List<PortraitStudent> unmatchSemester = new List<PortraitStudent>();
  1658. List<PortraitStudent> upsertDatas = new List<PortraitStudent>();
  1659. //细项类型不匹配的
  1660. List<PortraitStudent> unmatchItemScoreType = new List<PortraitStudent>();
  1661. string stusql = $"select c.id,c.classId,c.name,c.year from c where c.id in ({string.Join(",", students.Select(f => $"'{f.studentId}'"))})";
  1662. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Student)
  1663. .GetItemQueryIterator<Student>(queryText: stusql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Base-{schoolCode}") }))
  1664. {
  1665. var student = students.Find(x => x.studentId.Equals(item.id));
  1666. student.classId = item.classId;
  1667. studentsBases.Add((item, student));
  1668. //if ($"{item.classId}".Equals($"{student.classId}"))
  1669. //{
  1670. // studentsBases.Add((item,student));
  1671. //}
  1672. //else {
  1673. // unmatchStuInfo.Add(student);
  1674. //}
  1675. }
  1676. var unexist = students.FindAll(z => !studentsBases.Select(z => z.studentBase.id).Contains(z.studentId));
  1677. if (unexist.Any())
  1678. {
  1679. unmatchStuInfo.AddRange(unexist);
  1680. }
  1681. Period period = schoolBase.period.Find(x => x.id.Equals($"{periodId}"));
  1682. if (period == null)
  1683. {
  1684. return responseData = new() { code = RespondCode.NotFound, msg = "periodId不存在" };
  1685. }
  1686. else
  1687. {
  1688. bool periodChange = false;
  1689. if (!period.semesters.Any())
  1690. {
  1691. //未设置学期则默认
  1692. period.semesters.Add(new Semester
  1693. {
  1694. id = Guid.NewGuid().ToString(),
  1695. name = "第一学期",
  1696. start = 1,
  1697. month = 9,
  1698. day = 1
  1699. }); period.semesters.Add(new Semester
  1700. {
  1701. id = Guid.NewGuid().ToString(),
  1702. name = "第二学期",
  1703. start = 0,
  1704. month = 3,
  1705. day = 1
  1706. });
  1707. periodChange = true;
  1708. }
  1709. //是否需要创建科目
  1710. if (!$"{subjectId}".Equals("subject_art", StringComparison.OrdinalIgnoreCase) || !$"{subjectId}".Equals("subject_intelligence", StringComparison.OrdinalIgnoreCase))
  1711. {
  1712. var bind = period.subjects.Find(x => !string.IsNullOrWhiteSpace(x.bindId) && x.bindId.Equals($"{subjectId}", StringComparison.OrdinalIgnoreCase));
  1713. if (bind == null)
  1714. {
  1715. string subjectName = "";
  1716. switch (true)
  1717. {
  1718. case bool when $"{subjectId}".Equals("subject_sport"):
  1719. subjectName = "体育";
  1720. break;
  1721. case bool when $"{subjectId}".Equals("subject_virtue"):
  1722. subjectName = "德育";
  1723. break;
  1724. case bool when $"{subjectId}".Equals("subject_labour"):
  1725. subjectName = "劳动";
  1726. break;
  1727. //case bool when $"{subjectId}".Equals("subject_music"):
  1728. // subjectName = "音乐";
  1729. // break;
  1730. //case bool when $"{subjectId}".Equals("subject_painting"):
  1731. // subjectName = "美术";
  1732. // break;
  1733. }
  1734. if (!string.IsNullOrWhiteSpace(subjectName))
  1735. {
  1736. var subName = period.subjects.Find(z => z.name.Contains(subjectName));
  1737. if (subName != null)
  1738. {
  1739. subName.bindId = $"{subjectId}";
  1740. }
  1741. else
  1742. {
  1743. period.subjects.Add(new Subject { id = Guid.NewGuid().ToString(), name = subjectName, bindId = $"{subjectId}", type = 1 });
  1744. }
  1745. periodChange = true;
  1746. }
  1747. }
  1748. }
  1749. //是否要创建艺术类的 音乐,美术科目
  1750. if ($"{subjectId}".Equals("subject_art", StringComparison.OrdinalIgnoreCase))
  1751. {
  1752. var bind_music = period.subjects.Find(x => !string.IsNullOrWhiteSpace(x.bindId) && x.bindId.Equals("subject_music", StringComparison.OrdinalIgnoreCase));
  1753. if (bind_music != null)
  1754. {
  1755. string subjectName = "音乐";
  1756. var subName = period.subjects.Find(z => z.name.Contains(subjectName));
  1757. if (subName != null)
  1758. {
  1759. subName.bindId = "subject_music";
  1760. }
  1761. else
  1762. {
  1763. period.subjects.Add(new Subject { id = Guid.NewGuid().ToString(), name = subjectName, bindId = "subject_music", type = 1 });
  1764. }
  1765. periodChange = true;
  1766. }
  1767. var bind_painting = period.subjects.Find(x => !string.IsNullOrWhiteSpace(x.bindId) && x.bindId.Equals("subject_painting", StringComparison.OrdinalIgnoreCase));
  1768. if (bind_painting != null)
  1769. {
  1770. string subjectName = "美术";
  1771. var subName = period.subjects.Find(z => z.name.Contains(subjectName));
  1772. if (subName != null)
  1773. {
  1774. subName.bindId = "subject_painting";
  1775. }
  1776. else
  1777. {
  1778. period.subjects.Add(new Subject { id = Guid.NewGuid().ToString(), name = subjectName, bindId = "subject_painting", type = 1 });
  1779. }
  1780. periodChange = true;
  1781. }
  1782. }
  1783. if (periodChange)
  1784. {
  1785. await client.GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync<School>(schoolBase, $"{schoolCode}", new PartitionKey("Base"));
  1786. }
  1787. List<Semester> sortedSemesters = SchoolService.SortSemester(period.semesters);
  1788. foreach (var studentInfo in studentsBases)
  1789. {
  1790. Student student = studentInfo.studentBase;
  1791. string studentId = studentInfo.studentBase.id;
  1792. string classId = studentInfo.studentBase.classId;
  1793. List<SemesterData> semesterDatas = studentInfo.portrait.semesterData;
  1794. if (semesterDatas.Any())
  1795. {
  1796. semesterDatas.ForEach(data =>
  1797. {
  1798. if (!string.IsNullOrWhiteSpace(data.semesterId))
  1799. {
  1800. var semester = period.semesters.Find(s => s.id.Equals(data.semesterId));
  1801. //如果找到对应的semesterId则直接使用当前semesterId
  1802. if (semester == null)
  1803. {
  1804. //先处理,最后再检查。
  1805. data.semesterId = $"{data.semesterId}--semesterId学期无效";
  1806. if (data.semester > 0)
  1807. {
  1808. int count = period.semesters.Count();
  1809. if (count >= data.semester)
  1810. {
  1811. data.semesterId = sortedSemesters[data.semester - 1].id;
  1812. }
  1813. else
  1814. {
  1815. data.semesterId = $"{data.semester}--semester学期无效";
  1816. }
  1817. }
  1818. else
  1819. {
  1820. data.semesterId = $"{data.semester}--semester学期无效";
  1821. //无效的学期数
  1822. }
  1823. }
  1824. }
  1825. else
  1826. {
  1827. data.semesterId = $"{data.semesterId}--semesterId学期无效";
  1828. if (data.semester > 0)
  1829. {
  1830. int count = period.semesters.Count();
  1831. if (count >= data.semester)
  1832. {
  1833. data.semesterId = sortedSemesters[data.semester - 1].id;
  1834. }
  1835. else
  1836. {
  1837. data.semesterId = $"{data.semester}--semester学期无效";
  1838. }
  1839. }
  1840. else
  1841. {
  1842. data.semesterId = $"{data.semester}--semester学期无效";
  1843. //无效的学期数
  1844. }
  1845. }
  1846. });
  1847. var noSemesterDatas = semesterDatas.Where(z => z.semesterId.Contains("学期无效")).ToList();
  1848. if (noSemesterDatas.Any())
  1849. {
  1850. unmatchSemester.Add(new PortraitStudent
  1851. {
  1852. studentId = studentInfo.portrait.studentId,
  1853. name = studentInfo.portrait.name,
  1854. classId = studentInfo.portrait.classId,
  1855. semesterData = noSemesterDatas,
  1856. });
  1857. }
  1858. var okSemesterDatas = semesterDatas.Where(z => !z.semesterId.Contains("学期无效"));
  1859. if (okSemesterDatas.Any())
  1860. {
  1861. upsertDatas.Add(new PortraitStudent
  1862. {
  1863. studentId = studentInfo.portrait.studentId,
  1864. name = studentInfo.portrait.name,
  1865. classId = studentInfo.portrait.classId,
  1866. semesterData = okSemesterDatas.ToList(),
  1867. });
  1868. }
  1869. var ids = okSemesterDatas.Select(k => $"{k.year}-{k.semesterId}-{studentId}");
  1870. if (ids.Any())
  1871. {
  1872. List<OverallEducation> overallEducations = new List<OverallEducation>();
  1873. string sql = $"select value c from c where c.id in ({string.Join(",", ids.Select(f => $"'{f}'"))})" +
  1874. $" and c.studentId ='{studentId}' and c.schoolCode='{schoolCode}' and c.periodId='{periodId}' and c.classId='{classId}'";
  1875. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Student)
  1876. .GetItemQueryIterator<OverallEducation>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"OverallEducation-{schoolCode}") }))
  1877. {
  1878. overallEducations.Add(item);
  1879. }
  1880. var nodbids = ids.Except(overallEducations.Select(x => x.id));
  1881. var newDatas = semesterDatas.FindAll(k => nodbids.Contains($"{k.year}-{k.semesterId}-{studentId}"));
  1882. var updateDatas = semesterDatas.FindAll(k => overallEducations.Select(z => z.id).Contains($"{k.year}-{k.semesterId}-{studentId}"));
  1883. List<OverallEducation> newOverallEducations = new List<OverallEducation>();
  1884. newDatas.ForEach(z =>
  1885. {
  1886. //处理新增的学生学期画像
  1887. var overallEducation = newOverallEducations.Find(o => o.id.Equals($"{z.year}-{z.semesterId}-{studentId}") && o.code.Equals($"OverallEducation-{schoolCode}"));
  1888. if (overallEducation == null)
  1889. {
  1890. overallEducation = new OverallEducation
  1891. {
  1892. id = $"{z.year}-{z.semesterId}-{studentId}",
  1893. code = $"OverallEducation-{schoolCode}",
  1894. pk = "OverallEducation",
  1895. ttl = -1,
  1896. name = student.name,
  1897. classId = student.classId,
  1898. schoolCode = $"{schoolCode}",
  1899. semesterId = z.semesterId,
  1900. year = z.year,
  1901. periodId = $"{periodId}",
  1902. stuYear = student.year,
  1903. studentId = student.id,
  1904. };
  1905. newOverallEducations.Add(overallEducation);
  1906. }
  1907. });
  1908. if (newOverallEducations.Any())
  1909. {
  1910. (newOverallEducations, unmatchItemScoreType) = FillSemesterData(studentId, $"{subjectId}", newOverallEducations, unmatchItemScoreType, newDatas,period);
  1911. foreach (var edu in newOverallEducations)
  1912. {
  1913. await client.GetContainer(Constant.TEAMModelOS, Constant.Student).CreateItemAsync(edu, new PartitionKey(edu.code));
  1914. string key = $"OverallEducation:{edu.schoolCode}:{edu.periodId}:{edu.year}:{edu.semesterId}:{edu.classId}";
  1915. await _azureRedis.GetRedisClient(8).HashSetAsync(key, edu.studentId, edu.ToJsonString());
  1916. await _azureRedis.GetRedisClient(8).KeyExpireAsync(key, new TimeSpan(180 * 24, 0, 0));
  1917. }
  1918. }
  1919. if (overallEducations.Any())
  1920. {
  1921. (overallEducations, unmatchItemScoreType) = FillSemesterData(studentId, $"{subjectId}", overallEducations, unmatchItemScoreType, updateDatas, period);
  1922. foreach (var edu in overallEducations)
  1923. {
  1924. await client.GetContainer(Constant.TEAMModelOS, Constant.Student).ReplaceItemAsync(edu, edu.id, new PartitionKey(edu.code));
  1925. string key = $"OverallEducation:{edu.schoolCode}:{edu.periodId}:{edu.year}:{edu.semesterId}:{edu.classId}";
  1926. await _azureRedis.GetRedisClient(8).HashSetAsync(key, edu.studentId, edu.ToJsonString());
  1927. await _azureRedis.GetRedisClient(8).KeyExpireAsync(key, new TimeSpan(180 * 24, 0, 0));
  1928. }
  1929. }
  1930. }
  1931. }
  1932. }
  1933. }
  1934. return responseData = new() { data = new { unmatchStuInfo, unmatchSemester, unmatchItemScoreType, upsertDatas }, code = RespondCode.Ok, msg = "成功" };
  1935. }
  1936. catch (CosmosException cex) when (cex.Status == 404)
  1937. {
  1938. return new ResponseData<dynamic>() { code = RespondCode.NotFound, msg = "学校编码不存在" };
  1939. }
  1940. catch (Exception ex)
  1941. {
  1942. await _dingDing.SendBotMsg($"OpenApi,{Environment.GetEnvironmentVariable("Option:Location")} OpenApiService/UpsertStudentPortrait() ,参数json:{json.ToJsonString()} \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  1943. return new ResponseData<dynamic>() { code = RespondCode.Error, msg = "服务端异常" };
  1944. }
  1945. }
  1946. public static (List<OverallEducation> overallEducations, List<PortraitStudent> unmatchItemScoreType) FillSemesterData(string studentId, string subjectId, List<OverallEducation> overallEducations,List<PortraitStudent> unmatchItemScoreType, List<SemesterData> semestersDatas,Period period)
  1947. {
  1948. foreach (var z in semestersDatas)
  1949. {
  1950. var oedu = overallEducations.Find(x => x.id.Equals($"{z.year}-{z.semesterId}-{studentId}"));
  1951. if (oedu != null)
  1952. {
  1953. List<EducationScore> educationScores = null;
  1954. switch (true)
  1955. {
  1956. case bool when $"{subjectId}".Equals("subject_sport"):
  1957. educationScores = oedu.sports;
  1958. break;
  1959. case bool when $"{subjectId}".Equals("subject_virtue"):
  1960. educationScores = oedu.virtue;
  1961. break;
  1962. case bool when $"{subjectId}".Equals("subject_labour"):
  1963. educationScores = oedu.labour;
  1964. break;
  1965. case bool when $"{subjectId}".Equals("subject_intelligence"):
  1966. {
  1967. educationScores = oedu.intelligence;
  1968. //对评测需要验证 细项的具体信息
  1969. bool isunmatch = false;
  1970. foreach (var v in z.itemScore)
  1971. {
  1972. var subject = period.subjects.Find(b => b.id.Equals(v.type));
  1973. if (subject == null)
  1974. {
  1975. isunmatch = true;
  1976. }
  1977. }
  1978. if (isunmatch)
  1979. {
  1980. unmatchItemScoreType.Add(new PortraitStudent { classId = oedu.classId, name = oedu.name, studentId = oedu.studentId, semesterData = new List<SemesterData> { z } });
  1981. continue;
  1982. }
  1983. break;
  1984. }
  1985. case bool when $"{subjectId}".Equals("subject_art"):
  1986. {
  1987. educationScores = oedu.art;
  1988. //对艺术评测需要验证 细项的具体信息
  1989. bool isunmatch = false;
  1990. foreach (var v in z.itemScore)
  1991. {
  1992. var subject = period.subjects.Find(b =>!string .IsNullOrWhiteSpace(b.bindId) && b.bindId.Equals(v.type));
  1993. if (subject == null)
  1994. {
  1995. isunmatch = true;
  1996. }
  1997. }
  1998. if (isunmatch)
  1999. {
  2000. unmatchItemScoreType.Add(new PortraitStudent { classId = oedu.classId, name = oedu.name, studentId = oedu.studentId, semesterData = new List<SemesterData> { z } });
  2001. continue;
  2002. }
  2003. break;
  2004. }
  2005. default:
  2006. educationScores = new List<EducationScore>();
  2007. break;
  2008. }
  2009. var edu = educationScores.Find(m => m.examId.Equals(z.examId));
  2010. z.totalScore = z.totalScore <= 0 ? 100 : z.totalScore;
  2011. if (edu == null)
  2012. {
  2013. edu = new EducationScore();
  2014. educationScores.Add(edu);
  2015. }
  2016. edu.examId = z.examId;
  2017. edu.examDate = z.examDate;
  2018. edu.examName = z.examName;
  2019. edu.examType = z.examType;
  2020. edu.excellenceRate = z.excellenceRate;
  2021. edu.totalScore = z.totalScore;
  2022. edu.rate = z.sumScore / z.totalScore;
  2023. edu.level = z.sumScore / z.totalScore;
  2024. edu.sumScore = z.sumScore;
  2025. edu.passRate = z.passRate;
  2026. edu.itemScore = z.itemScore;
  2027. }
  2028. }
  2029. return (overallEducations, unmatchItemScoreType);
  2030. }
  2031. public static void GenApiTableRecord(AzureStorageFactory azureStorage)
  2032. {
  2033. //在开发模式时,自检 [ApiToken(Auth = "1")] 有重复的接口 https://teammodelos.table.core.chinacloudapi.cn/IESOpenApi
  2034. (List<OpenApi> openApis, List<ApiTokenAttribute> attributes) = ReflectorExtensions.GetOpenApi(new string[] { "TEAMModelOS" });
  2035. openApis.GroupBy(x => $"{x.PartitionKey}{x.RowKey}").ToList().ForEach(x =>
  2036. {
  2037. if (x.Count() > 1)
  2038. {
  2039. throw new Exception($"接口Auth重复定义{x.ToList()}");
  2040. }
  2041. });
  2042. var table = azureStorage.GetCloudTableClient().GetTableReference("IESOpenApi");
  2043. openApis = openApis.OrderBy(x => x.RowKey).ToList();
  2044. string tbqurey = $"PartitionKey {QueryComparisons.Equal} 'IES5-API' and RowKey {QueryComparisons.GreaterThanOrEqual} '{openApis.First().RowKey}' and RowKey {QueryComparisons.LessThanOrEqual} '{openApis.Last().RowKey}' ";
  2045. var apiResult = table.ExecuteQuerySegmented(new TableQuery<OpenApi>().Where(tbqurey), null);
  2046. List<OpenApi> apis = apiResult.Results;
  2047. //数据库历史数据处理
  2048. apis.ForEach(x =>
  2049. {
  2050. var api = openApis.Find(z => z.RowKey.Equals(x.RowKey));
  2051. if (api != null)
  2052. {
  2053. x.auth = api.auth;
  2054. x.name = api.name;
  2055. x.type = api.type;
  2056. x.url = api.url;
  2057. x.method = api.method;
  2058. }
  2059. });
  2060. openApis.RemoveAll(x => apis.Select(z => z.RowKey).Contains(x.RowKey));
  2061. openApis.AddRange(apis);
  2062. _ = table.SaveOrUpdateAll<OpenApi>(openApis);
  2063. string dataopenApis = openApis.ToJsonString();
  2064. (List<WebHook> webHooks, List<ApiTokenAttribute> _attributes) = ReflectorExtensions.GetWebHook(new string[] { "TEAMModelOS.SDK" });
  2065. webHooks.GroupBy(x => $"{x.PartitionKey}{x.RowKey}").ToList().ForEach(x =>
  2066. {
  2067. if (x.Count() > 1)
  2068. {
  2069. throw new Exception($"接口Auth重复定义{x.ToList()}");
  2070. }
  2071. });
  2072. webHooks = webHooks.OrderBy(x => x.RowKey).ToList();
  2073. tbqurey = $"PartitionKey {QueryComparisons.Equal} 'IES5-WEBHOOK' and RowKey {QueryComparisons.GreaterThanOrEqual} '{webHooks.First().RowKey}' and RowKey {QueryComparisons.LessThanOrEqual} '{webHooks.Last().RowKey}' ";
  2074. var hookResult = table.ExecuteQuerySegmented(new TableQuery<WebHook>().Where(tbqurey), null);
  2075. List<WebHook> hooks = hookResult.Results;
  2076. //数据库历史数据处理
  2077. hooks.ForEach(x =>
  2078. {
  2079. var api = webHooks.Find(z => z.RowKey.Equals(x.RowKey));
  2080. if (api != null)
  2081. {
  2082. x.auth = api.auth;
  2083. x.name = api.name;
  2084. x.ename = api.ename;
  2085. x.tname = api.tname;
  2086. x.type = api.type;
  2087. x.url = api.url;
  2088. x.method = api.method;
  2089. x.notice = api.notice;
  2090. }
  2091. });
  2092. webHooks.RemoveAll(x => hooks.Select(z => z.RowKey).Contains(x.RowKey));
  2093. webHooks.AddRange(hooks);
  2094. _ = table.SaveOrUpdateAll<WebHook>(webHooks);
  2095. string datawebHooks = webHooks.ToJsonString();
  2096. }
  2097. /// <summary>
  2098. /// 学生登录信息
  2099. /// </summary>
  2100. /// <param name="_azureCosmos"></param>
  2101. /// <param name="_dingDing"></param>
  2102. /// <param name="bizId"></param>
  2103. /// <param name="school"></param>
  2104. /// <param name="json"></param>
  2105. /// <returns></returns>
  2106. public static async Task<ResponseData<dynamic>> GetLoginStuInfo(AzureCosmosFactory _azureCosmos, DingDing _dingDing, Option _option, string bizId, string school, JsonElement json)
  2107. {
  2108. if (!json.TryGetProperty("idToken", out JsonElement _idToken)) return new ResponseData<dynamic>() { code = RespondCode.ParamsError, msg = "idToken参数错误", data = null };
  2109. JwtSecurityToken jwt = new($"{_idToken}");
  2110. var iss = jwt.Payload.Iss;
  2111. var stuId = jwt.Payload.Sub;
  2112. var scId = jwt.Payload.Azp;
  2113. try
  2114. {
  2115. var client = _azureCosmos.GetCosmosClient();
  2116. //if (!string.IsNullOrWhiteSpace($"{_idToken}") && JwtAuthExtension.ValidateApiToken($"{_idToken}", _option.JwtSecretKey))
  2117. //{
  2118. // JwtSecurityToken jwt = new($"{_idToken}");
  2119. //}
  2120. OStudent student = new();
  2121. jwt.Payload.TryGetValue("name", out object stuName);
  2122. jwt.Payload.TryGetValue("picture", out object stuPicture);
  2123. if (!jwt.Payload.TryGetValue("scope", out object scope)) return new ResponseData<dynamic>() { code = RespondCode.ParamsError, msg = "参数错误:scope", data = null };
  2124. if (!jwt.Payload.TryGetValue("roles", out object _roles)) return new ResponseData<dynamic>() { code = RespondCode.ParamsError, msg = "参数错误:roles", data = null };
  2125. jwt.Payload.TryGetValue("permissions", out object permissions);
  2126. jwt.Payload.TryGetValue("standard", out object standard);
  2127. jwt.Payload.TryGetValue("area", out object area);
  2128. jwt.Payload.TryGetValue("website", out object website);
  2129. List<string> roles = $"{_roles}".ToObject<List<string>>();
  2130. if (roles.Contains("student") && $"{scope}".Equals("student"))
  2131. {
  2132. if (!string.IsNullOrEmpty(stuId) && !string.IsNullOrEmpty(scId))
  2133. {
  2134. if (school.Equals(scId))
  2135. {
  2136. var responseStu = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").ReadItemStreamAsync(stuId, new PartitionKey($"Base-{scId}"));
  2137. if (responseStu.Status == 200)
  2138. {
  2139. JsonDocument jsonD = JsonDocument.Parse(responseStu.Content);
  2140. student = jsonD.RootElement.ToObject<OStudent>();
  2141. switch (student.gender)
  2142. {
  2143. case "M":
  2144. student.gender = "男";
  2145. break;
  2146. case "F":
  2147. student.gender = "女";
  2148. break;
  2149. case "N":
  2150. student.gender = "保密";
  2151. break;
  2152. }
  2153. }
  2154. else
  2155. { return new ResponseData<dynamic>() { code = RespondCode.NotFound, msg = "未找到该学生", data = new { id = stuId, schoolId = scId } }; }
  2156. }
  2157. else
  2158. { return new ResponseData<dynamic>() { code = RespondCode.NotFound, msg = "headers和idToken中的学校ID不匹配", data = null }; }
  2159. }
  2160. else
  2161. { return new ResponseData<dynamic>() { code = RespondCode.ParamsError, msg = "参数错误:Sub/scId", data = null }; }
  2162. }
  2163. else
  2164. { return new ResponseData<dynamic>() { code = RespondCode.ParamsError, msg = "参数错误:roles/Azp", data = null }; }
  2165. return new ResponseData<dynamic>() { code = RespondCode.Ok, msg = "成功", data = student };
  2166. }
  2167. catch (Exception ex)
  2168. {
  2169. await _dingDing.SendBotMsg($"OpenApi,{Environment.GetEnvironmentVariable("Option:Location")} OpenApiService/GetLoginStuInfo() 参数:stu:{stuId},school:{school},json:{json.ToJsonString()} \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  2170. return new ResponseData<dynamic>() { code = RespondCode.Error, msg = "服务器错误" };
  2171. }
  2172. }
  2173. /// <summary>
  2174. /// 获取学生详细信息
  2175. /// </summary>
  2176. /// <param name="_azureCosmos"></param>
  2177. /// <param name="_dingDing"></param>
  2178. /// <param name="bizId"></param>
  2179. /// <param name="school"></param>
  2180. /// <param name="json"></param>
  2181. /// <returns></returns>
  2182. public static async Task<ResponseData<dynamic>> GetStudentInfo(AzureCosmosFactory _azureCosmos, DingDing _dingDing, string bizId, string school, JsonElement json)
  2183. {
  2184. if (!json.TryGetProperty("ids", out JsonElement _ids)) return new ResponseData<dynamic>() { code = RespondCode.ParamsError, msg = "idToken参数错误", data = null };
  2185. try
  2186. {
  2187. List<string> ids = _ids.ToObject<List<string>>();
  2188. List<OStudent> student = new();
  2189. //List<OStudent> tmdId = new();
  2190. string sqlStu = $"select value(c) from c ";
  2191. if (ids.Count > 0)
  2192. sqlStu = $"select value(c) from c where c.id in ({string.Join(",", ids.Select(s => $"'{s}'"))})";
  2193. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<OStudent>(queryText: sqlStu, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{school}") }))
  2194. {
  2195. student.Add(item);
  2196. }
  2197. //string sqlTmd = $"select value(c) from c join s in c.schools where c.id in ({string.Join(",", ids.Select(s => $"'{s}'"))}) and s.schoolId='{school}'";
  2198. //await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<OStudent>(queryText: sqlTmd, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
  2199. //{
  2200. // tmdId.Add(item);
  2201. //}
  2202. return new ResponseData<dynamic>() { code = RespondCode.Ok, msg = "成功", data = student };
  2203. }
  2204. catch (Exception ex)
  2205. {
  2206. await _dingDing.SendBotMsg($"OpenApi,{Environment.GetEnvironmentVariable("Option:Location")} OpenApiService/GetLoginStuInfo() 参数:学生id集合:{_ids},school:{school},json:{json.ToJsonString()} \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  2207. return new ResponseData<dynamic>() { code = RespondCode.Error, msg = "服务器错误" };
  2208. }
  2209. }
  2210. }
  2211. public class OCourseBase
  2212. {
  2213. public string tmdname { get; set; }
  2214. public string courseName { get; set; }
  2215. public int attendCount { get; set; }
  2216. public int mCount { get; set; }
  2217. public List<string> groups { get; set; }
  2218. public long time { get; set; }
  2219. public List<Events> eves { get; set; }
  2220. public List<Videos> videos { get; set; }
  2221. }
  2222. public class Events
  2223. {
  2224. public string @event { get; set; }
  2225. public int freq { get; set; }
  2226. public long createTime { get; set; }
  2227. }
  2228. public class Videos
  2229. {
  2230. public string videoName { get; set; }
  2231. public string video { get; set; }
  2232. public int duration { get; set; }
  2233. public long startTime { get; set; }
  2234. }
  2235. }