TestController.cs 158 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076
  1. using Azure;
  2. using Microsoft.Azure.Cosmos;
  3. using Azure.Storage.Blobs.Models;
  4. using DinkToPdf;
  5. using DinkToPdf.Contracts;
  6. using Microsoft.AspNetCore.Hosting;
  7. using Microsoft.AspNetCore.Http;
  8. using Microsoft.AspNetCore.Mvc;
  9. using Microsoft.Extensions.Configuration;
  10. using Microsoft.Extensions.Options;
  11. using System;
  12. using System.Collections.Concurrent;
  13. using System.Collections.Generic;
  14. using System.IO;
  15. using System.Linq;
  16. using System.Net;
  17. using System.Net.Http;
  18. using System.Net.Http.Json;
  19. using System.Text;
  20. using System.Text.Json;
  21. using System.Threading.Tasks;
  22. using TEAMModelOS.Controllers.Third.LePei;
  23. using TEAMModelOS.Filter;
  24. using TEAMModelOS.Models;
  25. using TEAMModelOS.SDK;
  26. using TEAMModelOS.SDK.DI;
  27. using TEAMModelOS.SDK.DI.Mail;
  28. using TEAMModelOS.SDK.Extension;
  29. using TEAMModelOS.SDK.Models;
  30. using TEAMModelOS.SDK.Models.Cosmos.Common;
  31. using TEAMModelOS.SDK.Models.Service;
  32. using TEAMModelOS.SDK.Services;
  33. using static TEAMModelOS.SDK.Models.Teacher;
  34. using static TEAMModelOS.SDK.SchoolService;
  35. namespace TEAMModelOS.Controllers
  36. {
  37. [Route("test")]
  38. [ApiController]
  39. public class TestController : ControllerBase
  40. {
  41. private readonly IHttpClientFactory _httpClient;
  42. public IWebHostEnvironment _environment { get; set; }
  43. private readonly AzureStorageFactory _azureStorage;
  44. private readonly AzureRedisFactory _azureRedis;
  45. private readonly AzureCosmosFactory _azureCosmos;
  46. private readonly DingDing _dingDing;
  47. private readonly AzureServiceBusFactory _serviceBus;
  48. private readonly CoreAPIHttpService _coreAPIHttpService;
  49. private readonly Option _option;
  50. private readonly IPSearcher _searcher;
  51. public IConfiguration _configuration { get; set; }
  52. private readonly IConverter _converter;
  53. private readonly HttpTrigger _httpTrigger;
  54. private readonly AzureServiceBusFactory _azureService;
  55. private readonly SnowflakeId _snowflakeId;
  56. private readonly MailFactory _mailFactory;
  57. public TestController(MailFactory mailFactory,HttpTrigger httpTrigger, IConverter converter, IPSearcher searcher, IOptionsSnapshot<Option> option, CoreAPIHttpService coreAPIHttpService, IHttpClientFactory httpClient, IWebHostEnvironment environment, AzureCosmosFactory azureCosmos, AzureRedisFactory azureRedis, AzureStorageFactory azureStorage, IConfiguration configuration, AzureServiceBusFactory serviceBus, DingDing dingDing, AzureServiceBusFactory azureService, SnowflakeId snowflakeId)
  58. {
  59. _converter = converter;
  60. _azureCosmos = azureCosmos;
  61. _azureRedis = azureRedis;
  62. _azureStorage = azureStorage;
  63. _dingDing = dingDing;
  64. _serviceBus = serviceBus; _configuration = configuration;
  65. _environment = environment;
  66. _httpClient = httpClient;
  67. _option = option.Value;
  68. _coreAPIHttpService = coreAPIHttpService;
  69. _searcher = searcher;
  70. _httpTrigger = httpTrigger;
  71. _azureService=azureService;
  72. _snowflakeId=snowflakeId;
  73. _mailFactory = mailFactory;
  74. }
  75. //
  76. /// <summary>
  77. /// 移除已经废弃的StuCourse 数据
  78. /// </summary>
  79. /// <param name="file"></param>
  80. /// <param name="periodId"></param>
  81. /// <returns></returns>
  82. [HttpGet("test-str")]
  83. [RequestSizeLimit(102_400_000_00)] //最大10000m左右
  84. public async Task<IActionResult> Tes1t() {
  85. await TEAMModelOS.SDK.Models.Service.SystemService.LessonWeekly(_azureRedis, _azureCosmos, _coreAPIHttpService, _dingDing);
  86. return Ok( );
  87. }
  88. /// <summary>
  89. /// 移除已经废弃的StuCourse 数据
  90. /// </summary>
  91. /// <param name="file"></param>
  92. /// <param name="periodId"></param>
  93. /// <returns></returns>
  94. [HttpPost("test-accumulate")]
  95. [RequestSizeLimit(102_400_000_00)] //最大10000m左右
  96. public async Task<IActionResult> RemoveStuCourse(JsonElement json)
  97. {
  98. json.TryGetProperty("am", out JsonElement _am);
  99. json.TryGetProperty("pm", out JsonElement _pm);
  100. int am = 0;
  101. int pm = 0;
  102. _am.TryGetInt32(out am);
  103. _pm.TryGetInt32(out pm);
  104. var url = _configuration.GetValue<string>("HaBookAuth:CoreAPI");
  105. var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
  106. var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
  107. string location = "";
  108. if (_option.Location.Contains("China"))
  109. {
  110. location = "China";
  111. }
  112. else if (_option.Location.Contains("Global"))
  113. {
  114. location = "Global";
  115. }
  116. var client = _httpClient.CreateClient();
  117. var token = CoreTokenExtensions.CreateAccessToken(clientID, clientSecret, location).Result;
  118. if (client.DefaultRequestHeaders.Contains("Authorization"))
  119. {
  120. client.DefaultRequestHeaders.Remove("Authorization");
  121. client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token.AccessToken}");
  122. }
  123. else
  124. {
  125. client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token.AccessToken}");
  126. }
  127. List<CodeValue> notifys= await SystemService.AccumulateDaily(_configuration, _azureRedis,_azureCosmos,_azureStorage, _coreAPIHttpService,_dingDing,client, _snowflakeId, url,am ,pm );
  128. return Ok(new { notifys });
  129. }
  130. /*
  131. [
  132. {
  133. "id": "99a4a33b-e21b-44ac-80a1-b31dc40496e0",
  134. "name": "蒲江县提升工程2.0研训平台"
  135. },
  136. {
  137. "id": "f35e0031-a53f-45e5-b307-1cd39446a2cf",
  138. "name": "金牛区直属学校提升工程2.0研训平台"
  139. },
  140. {
  141. "id": "2c1b01fe-3641-464f-8499-7be95a489b7c",
  142. "name": "峨边彝族自治县提升工程2.0研训平台"
  143. },
  144. {
  145. "id": "870a5a6b-1ab3-461a-bdeb-baec19780ddb",
  146. "name": "金牛区非直属学校提升工程2.0研训平台"
  147. },
  148. {
  149. "id": "dd15017a-f361-4346-852e-8eee71d027ad",
  150. "name": "峨眉山提升工程2.0研训平台"
  151. },
  152. {
  153. "id": "3b5a9b06-a9ec-4bac-b1dd-f73f5519f637",
  154. "name": "乐山市井研县提升工程2.0研训平台"
  155. },
  156. {
  157. "id": "1680c1c5-14e4-4bc2-b4cb-1749a537a01f",
  158. "name": "宜宾市筠连县提升工程2.0研训平台"
  159. },
  160. {
  161. "id": "e6fb5d40-bd85-7327-cea8-ea5c642836d2",
  162. "name": "广安市岳池县提升工程2.0研训平台"
  163. },
  164. {
  165. "id": "b14668be-d2f0-4923-8bf6-a27d9cc9111d",
  166. "name": "犍为县提升工程2.0研训平台"
  167. },
  168. {
  169. "id": "f49a83de-6156-448a-93b1-f03d0da967d6",
  170. "name": "宜宾市屏山县提升工程2.0研训平台"
  171. },
  172. {
  173. "id": "4a37997a-12b1-4f21-876b-3d9ba940fe54",
  174. "name": "宜宾市屏山县提升工程2.0研训平台(非一线)"
  175. },
  176. {
  177. "id": "6104c377-f48f-4d4c-9b38-509f9ccb54db",
  178. "name": "武胜县提升工程2.0研训平台"
  179. }
  180. ]
  181. */
  182. /// <summary>
  183. /// 将区级下所以学校的研修数据封存
  184. /// </summary>
  185. /// <param name="data"></param>
  186. /// <returns></returns>
  187. [HttpPost("change-blob-to-archive")]
  188. [RequestSizeLimit(102_400_000_00)] //最大10000m左右
  189. public async Task<IActionResult> Change(JsonElement data)
  190. {
  191. IdName area = null;
  192. if (data.TryGetProperty("area", out JsonElement _area))
  193. {
  194. area= _area.ToObject<IdName>();
  195. }
  196. List<ScTeacher> teachers = new List<ScTeacher>();
  197. var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
  198. List<int> pids = new List<int>();
  199. if (data.TryGetProperty("pids", out JsonElement _pids))
  200. {
  201. pids=_pids.ToObject<List<int>>();
  202. }
  203. if (pids.IsNotEmpty()) {
  204. foreach (var p in pids)
  205. {
  206. List<ScTeacher> teachersTable= await table.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", "ScTeacher" }, { "ProjectItemID", p } });
  207. if (teachersTable.IsNotEmpty()) {
  208. teachers.AddRange(teachersTable);
  209. }
  210. }
  211. }
  212. HashSet<string> ids = teachers.Where(v => !string.IsNullOrWhiteSpace(v.tmdid)).Select(z => z.tmdid).ToHashSet();
  213. List<SchoolEconomy> economies = new List<SchoolEconomy>(0);
  214. if (area!= null)
  215. {
  216. string sql = $"select value c from c where c.areaId ='{area.id}'";
  217. List<School> schools = new List<School>();
  218. var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<School>(sql, "Base");
  219. if (result.list.IsNotEmpty())
  220. {
  221. schools.AddRange(result.list);
  222. }
  223. foreach (var school in schools)
  224. {
  225. double? ScoresYxpt = await _azureRedis.GetRedisClient(8).SortedSetScoreAsync($"Blob:Catalog:{school.id}", "yxpt");
  226. double? ScoresTrain = await _azureRedis.GetRedisClient(8).SortedSetScoreAsync($"Blob:Catalog:{school.id}", "train");
  227. double total = ((ScoresYxpt.HasValue ? ScoresYxpt.Value : 0)+(ScoresTrain.HasValue ? ScoresTrain.Value : 0))*1.0 /1073741824; //GB
  228. List<string> yxpts = await _azureStorage.GetBlobContainerClient(school.id).List("yxpt");
  229. HashSet<string> archive = new HashSet<string>();
  230. if (yxpts.IsNotEmpty()) {
  231. foreach (var uri in yxpts)
  232. {
  233. if (ids!=null && ids.Count>0)
  234. {
  235. bool has = false;
  236. foreach (var id in ids)
  237. {
  238. if (uri.Contains(id))
  239. {
  240. has = true;
  241. break;
  242. }
  243. }
  244. if (!has)
  245. {
  246. archive.Add($"https://teammodeltest.blob.core.chinacloudapi.cn/{school.id}/{uri}");
  247. }
  248. }
  249. else
  250. {
  251. archive.Add($"https://teammodeltest.blob.core.chinacloudapi.cn/{school.id}/{uri}");
  252. }
  253. }
  254. }
  255. List<string> trains = await _azureStorage.GetBlobContainerClient(school.id).List("train");
  256. if (trains.IsNotEmpty())
  257. {
  258. foreach (var uri in trains)
  259. {
  260. if (ids!=null && ids.Count>0)
  261. {
  262. bool has = false;
  263. foreach (var id in ids)
  264. {
  265. if (uri.Contains(id))
  266. {
  267. has = true;
  268. break;
  269. }
  270. }
  271. if (!has)
  272. {
  273. archive.Add($"https://teammodeltest.blob.core.chinacloudapi.cn/{school.id}/{uri}");
  274. }
  275. }
  276. else
  277. {
  278. archive.Add($"https://teammodeltest.blob.core.chinacloudapi.cn/{school.id}/{uri}");
  279. }
  280. }
  281. }
  282. if (archive.Count==0)
  283. {
  284. economies.Add(new SchoolEconomy { schoolId= school.id, schoolName= school.name, areaId=area.id, areaName=area.name, total=0, count=(yxpts!=null ? yxpts.Count : 0)+(trains!=null ? trains.Count : 0), archive=archive.Count });
  285. }
  286. else
  287. {
  288. //var pages = archive.Page(100);
  289. //foreach (var page in pages) {
  290. // if (page.Count()==0) { continue; }
  291. // try
  292. // {
  293. // await _azureStorage.GetBlobServiceClient().GetBlobBatchClient().SetBlobsAccessTierAsync(blobUris: page.Select(z => new Uri(z)), accessTier: AccessTier.Archive);
  294. // }
  295. // catch (Exception ex1)
  296. // {
  297. // var p20s = page.Page(20);
  298. // foreach (var p20 in p20s)
  299. // {
  300. // if (p20.Count()==0) { continue; }
  301. // try
  302. // {
  303. // await _azureStorage.GetBlobServiceClient().GetBlobBatchClient().SetBlobsAccessTierAsync(blobUris: p20.Select(z => new Uri(z)), accessTier: AccessTier.Archive);
  304. // }
  305. // catch (Exception ex2)
  306. // {
  307. // var p1s = p20.Page(1);
  308. // foreach (var p1 in p1s) {
  309. // if (p1.Count()==0) { continue; }
  310. // try
  311. // {
  312. // string path = p1.First().Replace($"https://teammodeltest.blob.core.chinacloudapi.cn/{school.id}/", "");
  313. // await _azureStorage.GetBlobContainerClient(school.id).GetBlobClient(path).SetAccessTierAsync(AccessTier.Archive);
  314. // }
  315. // catch (Exception ex3)
  316. // {
  317. // await _dingDing.SendBotMsg($"错误的链接地址:{p1.ToJsonString()}", GroupNames.成都开发測試群組);
  318. // }
  319. // }
  320. // }
  321. // }
  322. // }
  323. //}
  324. economies.Add(new SchoolEconomy { schoolId= school.id, schoolName= school.name, areaId=area.id, areaName=area.name, total=total, count=(yxpts!=null ? yxpts.Count : 0)+(trains!=null ? trains.Count : 0), archive=archive.Count });
  325. }
  326. }
  327. AreaEconomy economy = new AreaEconomy {id = area.id ,name = area.name, pk="AreaEconomy",code="AreaEconomy", economies= economies, sum= economies.Select(z => z.total).Sum(), count= economies.Select(z => z.count).Sum(), teachers= ids.ToList() };
  328. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).UpsertItemAsync(economy, new PartitionKey("AreaEconomy"));
  329. return Ok(new { economy });
  330. }
  331. else { return Ok(); }
  332. }
  333. public class AreaEconomy : CosmosEntity
  334. {
  335. public AreaEconomy(){
  336. pk="AreaEconomy";
  337. code="AreaEconomy";
  338. }
  339. public List<int> pids = new List<int>();
  340. public string name { get; set; }
  341. public List<SchoolEconomy> economies { get; set; } = new List<SchoolEconomy>();
  342. public double sum { get; set; }
  343. public long count { get; set; }
  344. /// <summary>
  345. /// 未被封存的教师
  346. /// </summary>
  347. public List<string> teachers = new List<string>();
  348. }
  349. public class SchoolEconomy {
  350. public string schoolId { get; set; }
  351. public string schoolName { get; set; }
  352. public string areaId { get; set; }
  353. public string areaName { get; set; }
  354. public double total { get; set; }
  355. public long count { get; set; }
  356. public long archive { get; set; }
  357. }
  358. [ProducesDefaultResponseType]
  359. [HttpPost("test-ru")]
  360. public async Task<IActionResult> FixSemester(JsonElement json)
  361. {
  362. await _azureStorage.GetBlobContainerClient("hscjzx").GetBlobClient("yxpt/standard3/jyzx/1639448922/691a16ca-b45a-4426-8e2d-162484af5d1d/B2-曹-微课方案.pdf").SetAccessTierAsync(AccessTier.Archive);
  363. await _azureStorage.GetBlobContainerClient("jlstcz").GetBlobClient("yxpt/standard14/jyzx/1657242924/b5625069-b8b7-431b-ab2a-643d9e2f80be/14岁少年沉迷网络,妈妈苦口婆心不起作用,偷偷躲在角落痛哭! 480P(标清)_format_2 (1).mp4").SetAccessTierAsync(AccessTier.Archive);
  364. //string url1 = HttpUtility.UrlPathEncode("https://teammodeltest.blob.core.chinacloudapi.cn/hscjzx/yxpt/standard3/jyzx/1639448922/691a16ca-b45a-4426-8e2d-162484af5d1d/B2-曹-微课方案.pdf");
  365. //string url2 = HttpUtility.UrlPathEncode("https://teammodeltest.blob.core.chinacloudapi.cn/jlstcz/yxpt/standard14/jyzx/1657242924/b5625069-b8b7-431b-ab2a-643d9e2f80be/14岁少年沉迷网络,妈妈苦口婆心不起作用,偷偷躲在角落痛哭! 480P(标清)_format_2 (1).mp4");
  366. //await _azureStorage.GetBlobServiceClient().GetBlobBatchClient().SetBlobsAccessTierAsync(
  367. // blobUris: new Uri[] { new Uri(url1),
  368. // new Uri(url2) }, accessTier: AccessTier.Archive);
  369. double? Scores = await _azureRedis.GetRedisClient(8).SortedSetScoreAsync($"Blob:Catalog:ssjxx", "yxpt");
  370. //await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = "yxpt", name = $"ssjxx" }, _serviceBus, _configuration, _azureRedis);
  371. //await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = "train", name = $"ssjxx" }, _serviceBus, _configuration, _azureRedis);
  372. //await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = "survey", name = $"ssjxx" }, _serviceBus, _configuration, _azureRedis);
  373. //await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = "records", name = $"ssjxx" }, _serviceBus, _configuration, _azureRedis);
  374. //await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = "homework", name = $"ssjxx" }, _serviceBus, _configuration, _azureRedis);
  375. //await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = "exam", name = $"ssjxx" }, _serviceBus, _configuration, _azureRedis);
  376. string topicName= "dep-active-task";
  377. List< string> msgStrs = new List< string>();
  378. //var client = new ServiceBusAdministrationClient("Endpoint=sb://teammodelos.servicebus.chinacloudapi.cn/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=Sy4h4EQ8zP+7w/lOLi1X3tGord/7ShFHimHs1vC50Dc=");
  379. //var subsPages = client.GetSubscriptionsAsync(topicName);
  380. //await foreach (var page in subsPages.AsPages()) {
  381. // var subs= page.Values;
  382. // foreach (var sub in subs) {
  383. // var receiver = _azureService.GetServiceBusClient().CreateReceiver( topicName, sub.SubscriptionName, new ServiceBusReceiverOptions
  384. // {
  385. // ReceiveMode = ServiceBusReceiveMode.PeekLock
  386. // });
  387. // var scheduledMessages = await receiver.PeekMessagesAsync(100);
  388. // foreach (var message in scheduledMessages)
  389. // {
  390. // Console.WriteLine($"Scheduled Message: {message.Body}");
  391. // Console.WriteLine($"Scheduled Enqueue Time: {message.ScheduledEnqueueTime}");
  392. // Console.WriteLine("--------------------");
  393. // }
  394. // await receiver.CloseAsync();
  395. // }
  396. //}
  397. return Ok(msgStrs);
  398. //await _azureStorage.GetBlobContainerClient("0-public").GetBlobClient("winteach.cn_nginx.zip").SetAccessTierAsync(AccessTier.Archive);
  399. //await _azureStorage.GetBlobServiceClient().GetBlobBatchClient().SetBlobsAccessTierAsync(
  400. // blobUris: new Uri[] { new Uri("https://teammodeltest.blob.core.chinacloudapi.cn/0-public/test.md"),
  401. // new Uri("https://teammodeltest.blob.core.chinacloudapi.cn/0-public/pay.html") },accessTier:AccessTier.Archive);
  402. //var cm = _azureRedis.GetConnectionMultiplexer();
  403. //var keys = cm.GetServer(cm.GetEndPoints()[0]).Keys(cm.GetDatabase(8).Database,"Blob:Catalog*");
  404. //List<string> ks = new List<string>();
  405. //foreach (var key in keys)
  406. //{
  407. // ks.Add(key.ToString());
  408. //}
  409. //var result4 = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<ExamInfo>($"select value c from c where c.pk='Exam'and c.owner='teacher'", null, pageSize: 200);
  410. //var result0 = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<ExamInfo>($"select value c from c where c.pk='Exam'and c.owner='teacher' and STARTSWITH(c.code,'Exam-')", null, pageSize: 200);
  411. //var result1 = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<ExamInfo>($"select value c from c where c.pk='Exam' and c.owner='teacher' and contains(c.code,'Exam-')", null, pageSize: 200);
  412. //var result2 = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<ExamInfo>($"select value c from c where c.pk='Exam' and c.owner='school' and contains(c.code,'Exam-hbc')", null, pageSize: 200);
  413. //var result3 = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<ExamInfo>($"select value c from c where c.pk='Exam' and c.owner='school' ", "Exam-hbcn", pageSize: 200);
  414. //return Ok(new { ru4 = result4.ru, count4 = result4.list.Count, ru0 = result0.ru, count0 = result0.list.Count(), ru1 = result1.ru, count1 = result1.list.Count(), ru2 = result2.ru, count2 = result2.list.Count(), ru3 = result3.ru, count3 = result3.list.Count() });
  415. }
  416. /// <summary>
  417. /// 测试五育画像数据推送
  418. /// </summary>
  419. /// <param name="json"></param>
  420. /// <returns></returns>
  421. [ProducesDefaultResponseType]
  422. [HttpPost("period")]
  423. public async Task<IActionResult> period(JsonElement json)
  424. {
  425. List<string> names = new List<string>();
  426. if (json.TryGetProperty("names", out JsonElement _names))
  427. {
  428. names= _names.ToObject<List<string>>();
  429. }
  430. List<Period> periods = new List<Period>();
  431. if (json.TryGetProperty("period", out JsonElement _period))
  432. {
  433. foreach (var name in names) {
  434. Period period = _period.ToObject<Period>();
  435. period.name= name;
  436. period.id= Guid.NewGuid().ToString();
  437. period.semesters.ForEach(z => z.id= Guid.NewGuid().ToString());
  438. period.analysis.type.ForEach(z => z.id= Guid.NewGuid().ToString());
  439. period.subjectCount=0;
  440. periods.Add(period);
  441. }
  442. }
  443. return Ok(periods);
  444. }
  445. /// <summary>
  446. /// 测试五育画像数据推送
  447. /// </summary>
  448. /// <param name="json"></param>
  449. /// <returns></returns>
  450. [ProducesDefaultResponseType]
  451. [HttpPost("import-table")]
  452. public async Task<IActionResult> ImportTable(JsonElement json)
  453. {
  454. List<LPSchool> schools = json.ToObject<List<LPSchool>>();
  455. var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
  456. await table.BatchInsertAsync (schools);
  457. return Ok(schools);
  458. }
  459. /// <summary>
  460. /// 测试五育画像数据推送
  461. /// </summary>
  462. /// <param name="json"></param>
  463. /// <returns></returns>
  464. [ProducesDefaultResponseType]
  465. [HttpPost("test-upsert-student-portrait")]
  466. public async Task<IActionResult> TestUpsertStudentPortrait(JsonElement json) {
  467. var data = await _httpTrigger.RequestHttpTrigger(json, _option.Location, "upsert-student-portrait");
  468. return Ok(data.json.ToObject<JsonElement>());
  469. }
  470. /// <summary>
  471. ///
  472. /// </summary>
  473. /// <param name="json"></param>
  474. /// <returns></returns>
  475. [ProducesDefaultResponseType]
  476. [HttpPost("transform-lessonrecord-overalleducation")]
  477. public async Task<IActionResult> TransformLessonrecordOveralleducation(JsonElement json) {
  478. //string msg = json.ToString();
  479. //var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
  480. //var messageChange = new ServiceBusMessage(msg);
  481. //messageChange.ApplicationProperties.Add("name", "LessonRecordEvent");
  482. //await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageChange);
  483. string sql = "select value c from c where c.pk='StudentScoreRecord' and c.userType='student' and c.school<>null and c.school<>'' ";
  484. List<StudentScoreRecord> studentScores = new List<StudentScoreRecord>();
  485. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).GetItemQueryIteratorSql<StudentScoreRecord>(sql)) {
  486. studentScores.Add(item);
  487. }
  488. var group = studentScores.GroupBy(z => z.school);
  489. string schoolSql = $"select value c from c where c.id in ({string.Join(",",group.Select(x=>$"'{x.Key}'"))})";
  490. var resultScool= await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<School>(schoolSql,"Base");
  491. foreach(var item in group)
  492. {
  493. var list = item.ToList();
  494. var stuids = list.Select(z => z.stuid);
  495. string studentSql = $"select value c from c where c.id in ({string.Join(",", stuids.Select(x => $"'{x}'"))})";
  496. var resultStuden = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).GetList<Student>(studentSql, $"Base-{item.Key}");
  497. foreach (var sturecord in list) {
  498. HashSet<OverallEducation> overallEducations = new HashSet<OverallEducation>();
  499. var studentBase = resultStuden.list.Find(x => x.id.Equals(sturecord.stuid, StringComparison.OrdinalIgnoreCase));
  500. var schoolBase = resultScool.list.Find(x => x.id.Equals(sturecord.school, StringComparison.OrdinalIgnoreCase));
  501. if (studentBase == null) {
  502. continue;
  503. }
  504. var period = schoolBase.period.Find(x => x.id.Equals($"{studentBase.periodId}"));
  505. foreach (var record in sturecord.lessonRecords) {
  506. if (record.time > 1000000000000) {
  507. (Semester currSemester, int studyYear, DateTimeOffset currSemesterDate, DateTimeOffset date, DateTimeOffset nextSemester) dataSemester = SchoolService.GetSemester(period, record.time);
  508. string oid = $"{dataSemester.studyYear}-{dataSemester.currSemester.id}-{sturecord.stuid}";
  509. string ocode = $"OverallEducation-{sturecord.school}";
  510. OverallEducation overallEducation = overallEducations.Where(o => o.id.Equals(oid, StringComparison.OrdinalIgnoreCase) && o.code.Equals(ocode, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
  511. if (overallEducation != null)
  512. {
  513. var hasrecord = overallEducation.lessonScore.Find(x => x.lessonId.Equals(record.lessonId));
  514. if (hasrecord != null)
  515. {
  516. hasrecord.gscore = record.gscore;
  517. hasrecord.pscore = record.pscore;
  518. hasrecord.tscore = record.tscore;
  519. hasrecord.tmdid = record.tmdid;
  520. hasrecord.school = record.school;
  521. hasrecord.scope = record.scope;
  522. hasrecord.lessonId = record.lessonId;
  523. hasrecord.courseId = record.courseId;
  524. hasrecord.periodId = record.periodId;
  525. hasrecord.subjectId = record.subjectId;
  526. hasrecord.time = record.time;
  527. }
  528. else
  529. {
  530. overallEducation.lessonScore.Add(
  531. new StudentLessonRecord
  532. {
  533. gscore = record.gscore,
  534. pscore = record.pscore,
  535. tscore = record.tscore,
  536. tmdid = record.tmdid,
  537. school = record.school,
  538. scope = record.scope,
  539. lessonId = record.lessonId,
  540. courseId = record.courseId,
  541. periodId = record.periodId,
  542. subjectId = record.subjectId,
  543. time = record.time
  544. }
  545. );
  546. }
  547. }
  548. else {
  549. ResponseMessage response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).ReadItemStreamAsync(oid, new PartitionKey(ocode));
  550. if (response.StatusCode != HttpStatusCode.OK)
  551. {
  552. overallEducation = new OverallEducation
  553. {
  554. id = oid,
  555. code = $"OverallEducation-{sturecord.school}",
  556. pk = "OverallEducation",
  557. ttl = -1,
  558. name = studentBase.name,
  559. classId = studentBase?.classId,
  560. schoolCode = $"{sturecord.school}",
  561. semesterId = dataSemester.currSemester.id,
  562. year = dataSemester.studyYear,
  563. periodId = $"{period.id}",
  564. stuYear = studentBase.year,
  565. studentId = studentBase.id,
  566. lessonScore = new List<StudentLessonRecord>
  567. {
  568. new StudentLessonRecord
  569. {
  570. gscore = record.gscore,
  571. pscore = record.pscore,
  572. tscore = record.tscore,
  573. tmdid = record.tmdid,
  574. school = record.school,
  575. scope = record.scope,
  576. lessonId = record.lessonId,
  577. courseId = record.courseId,
  578. periodId = record.periodId,
  579. subjectId = record.subjectId,
  580. time= record.time
  581. }
  582. }
  583. };
  584. }
  585. else
  586. {
  587. overallEducation = JsonDocument.Parse(response.Content).RootElement.ToObject<OverallEducation>();
  588. var hasrecord = overallEducation.lessonScore.Find(x => x.lessonId.Equals(record.lessonId));
  589. if (hasrecord != null)
  590. {
  591. hasrecord.gscore = record.gscore;
  592. hasrecord.pscore = record.pscore;
  593. hasrecord.tscore = record.tscore;
  594. hasrecord.tmdid = record.tmdid;
  595. hasrecord.school = record.school;
  596. hasrecord.scope = record.scope;
  597. hasrecord.lessonId = record.lessonId;
  598. hasrecord.courseId = record.courseId;
  599. hasrecord.periodId = record.periodId;
  600. hasrecord.subjectId = record.subjectId;
  601. hasrecord.time = record.time;
  602. }
  603. else
  604. {
  605. overallEducation.lessonScore.Add(
  606. new StudentLessonRecord
  607. {
  608. gscore = record.gscore,
  609. pscore = record.pscore,
  610. tscore = record.tscore,
  611. tmdid = record.tmdid,
  612. school = record.school,
  613. scope = record.scope,
  614. lessonId = record.lessonId,
  615. courseId = record.courseId,
  616. periodId = record.periodId,
  617. subjectId = record.subjectId,
  618. time = record.time
  619. }
  620. );
  621. }
  622. }
  623. overallEducations.Add(overallEducation);
  624. }
  625. }
  626. }
  627. foreach (var overallEducation in overallEducations) {
  628. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).UpsertItemAsync(overallEducation, partitionKey: new PartitionKey(overallEducation.code));
  629. }
  630. }
  631. }
  632. return Ok();
  633. }
  634. /// <summary>
  635. ///
  636. /// </summary>
  637. /// <param name="json"></param>
  638. /// <returns></returns>
  639. [ProducesDefaultResponseType]
  640. [HttpPost("check-art-result")]
  641. public async Task<IActionResult> CheckArtResult(JsonElement json)
  642. {
  643. List<StudentArtResult> art_idNames = new List<StudentArtResult>();
  644. string sqlSchool = "select value c from c where c.areaId='7a51072f-b329-4e74-99e0-ba0407ba8926'";
  645. List<School> schools = new List<School>();
  646. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School)
  647. .GetItemQueryIteratorSql<School>(sqlSchool, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
  648. {
  649. schools.Add(item);
  650. }
  651. string sql = @"SELECT value c FROM c where c.pk='ArtResult' and c.artId in('770fbaaa-a9e8-4d45-a322-3c6d6e50a8f7',
  652. '1e59bb5f-984f-406d-83a2-48ef1ce60a75',
  653. '33fc9276-60c1-4663-8c42-2e44a138a874',
  654. '4eada95b-a408-4a66-bd6c-c61c6057d505',
  655. 'f61b32c6-2f86-4ae6-ac25-1961df0f443a',
  656. '4d974b69-e104-45db-8047-b4cbc43ebc98',
  657. 'efb8f6ed-74b9-43b7-b8e5-c61d92441ed9',
  658. '070d8ce5-253c-404b-80b7-12cbc234ddae',
  659. 'fdd6c34b-44c2-42e9-9cd4-66c01b7103da',
  660. 'b1cf6fed-a4ea-4d06-b15d-3941fba973de',
  661. '67cd2be9-e307-4d35-8249-6d4e7380d15c',
  662. 'f0481d0e-ab74-4117-8600-a375a206e283',
  663. '7a809ab3-4081-4a23-8127-9a362f9af8ff',
  664. '673684e2-1dc3-48d9-a21f-207cc40a68ba',
  665. '35e4da67-0fb9-4683-9fac-9c9b1c197f24',
  666. '893b9871-8518-4f70-97e5-58ceb4c1b504',
  667. '0cd4ea92-4697-468a-a2fd-2f0e1cd53525',
  668. 'd9fec69f-2532-408b-bc25-98a33edf7200',
  669. '02b68eed-29f2-49c1-a91f-c1e35dd8ce64',
  670. 'edaf8c12-9b0b-4b31-baff-3e9b926b401a',
  671. '472bbdc9-c287-4b18-9502-7f34d15172a8',
  672. '41f67e3c-6c7f-46e9-bc39-ec8d6ae9a495',
  673. 'ffea1c6b-3fb7-40d4-921b-e1dc46d15410',
  674. '079fa190-fc18-46b9-bcb9-a4b6e2cd902d',
  675. 'a0e778e8-2590-431e-b761-4929fa143762',
  676. '374a571a-6d5c-4a8a-ab57-6e79b8b8ff0a',
  677. '1db3838e-d7cd-4c77-af70-d3854262d33e',
  678. '7b8a2f53-3b90-48f1-bd0b-bb5be843656a',
  679. 'e5c24756-1ea3-46cf-8f0f-357ec280e42c',
  680. '1b713f31-7e0b-4cb5-84f1-0342db618a6d',
  681. '1794bc46-d0fb-4ea9-8ff8-2f813affe495',
  682. 'b9d54179-7eaf-426b-a44f-9018e6c4ffa7',
  683. '3145e47a-21e5-4cdf-a992-72b9e47c7bad',
  684. 'bdaab0b2-f8d0-4c1b-821c-95b4a2371c42',
  685. 'd39f74df-dc65-44d4-8463-41af1a4b186d',
  686. '79e83de1-4e64-4ef3-b24e-fe4e877e683b',
  687. 'bf3aaff3-1a86-42c8-89d7-4b9d6147d37f',
  688. 'ad3742eb-9e46-43f8-9644-ecb498082810',
  689. '66a3d74b-3946-42c3-a2d2-0bc6704c86ec',
  690. 'ec75e499-f432-41d4-b6dd-5548358b657d',
  691. '70ef5724-f875-4e2e-bda8-58fd2457c2a7',
  692. '60c03852-8c97-4cb0-a232-e0734eaebe96',
  693. '4eefe05d-3df9-4f27-804b-53dd7bc5f4ab',
  694. 'b82ff879-5474-4b31-b3e6-3174361a4fd0',
  695. '09489fef-5490-4b5e-802b-74d1be2c5515',
  696. '1a7d8d51-f828-4f15-9859-33937b41b9e4',
  697. '9e591e75-538e-426d-862d-b043c13e822a',
  698. '71cd894a-e82d-49ff-a204-a64a2eb6f332',
  699. '70103a11-095b-4d01-b3ea-0ed2e388445f',
  700. 'b40d4952-396d-49f3-ba2d-6aeba1d940d9',
  701. '149a12ae-7c5d-444c-ac34-17af88cf653e',
  702. '8c1b2180-4a81-4f6b-989a-b971dbeae082',
  703. '079107f5-7bf5-4955-a39c-85dec9715e60',
  704. 'f9abe967-dbce-46d7-a60f-d9a2e6866ec6',
  705. 'b4684520-cf0c-473c-aa3a-ea5ba5d398d3',
  706. '0839abf0-07e7-4c0d-b818-54d451a6265a',
  707. '6abc82c7-928b-43bf-8c5d-f5a5d7c55a4d',
  708. '544577d3-c4b0-491f-a041-18cc07e711ca',
  709. '2efddd68-0bbc-4dba-a594-f7f8532f519d',
  710. '725f2665-1015-4563-9044-f4061accdf67',
  711. '739aa426-a359-4515-85ef-1efe605c0b73',
  712. '8dcde32c-3a77-4bf5-84a3-ec4d7a78413d',
  713. '4a396e8b-babb-47ee-b6ed-db2124d5c39d',
  714. '55f4594b-c13b-48b8-82f1-563751d48e9e',
  715. '3cc1bd57-bf4e-4933-ac6b-7cdb0e8e2dc1',
  716. '380511bf-2b15-4b90-b8c8-3464c2c6e18c',
  717. '12378c30-0c1d-4c84-8deb-5aaffaa2b45c',
  718. 'e247abc3-7083-4de5-a492-46e09e9bb341',
  719. 'ef826295-7a00-483d-945b-589c8fc0baf9',
  720. 'c1b056c5-0ebf-454a-bb56-3f6024e837d2',
  721. 'c513fe45-767c-4632-b6d3-9631c9bf8854',
  722. '9f7d087e-ba53-4167-9776-1e33a9a1cb61',
  723. 'b5f1a3f0-975f-441c-b6d0-3b8513b96d24',
  724. '92560ac8-a3a5-4aff-85e6-b7f72fc7e2fb',
  725. '898a7705-47f3-4f3b-a01e-1ec609ad4abf',
  726. '4c4349a0-ade4-4793-a435-15de7f3c299e',
  727. '473707f1-6f43-4611-adca-263604aa8e58',
  728. '88ee65ec-ec5c-4c5a-8539-8a8e931508ce',
  729. '4b12c255-5f44-4056-8ab6-d33721394ab2',
  730. '1f2f9ad3-e465-4152-afce-26715e3902af',
  731. 'bba7590c-735a-41c3-a501-ab4285fc36e8',
  732. '51c7426f-934f-4a18-bc1f-053e994969cc',
  733. '9ec15578-a78b-4f9d-ae8c-f15677d03d0a',
  734. '6fc632fe-5833-4c26-a079-70f9a3fa1957',
  735. '86a886f5-e540-4f57-abfd-cee4e3d328ab',
  736. '66e50efa-c3c4-4e3e-8892-5ebdec85a008',
  737. '2b66ee3b-e74a-446a-a92d-9cdc11a43123',
  738. '09533510-ec3a-4c45-8220-097a2a7e4237',
  739. 'be879d1f-1ccd-4e5f-9871-449a736a9279',
  740. '2371ba86-0598-44eb-99de-c73b7cca15db',
  741. '77f87528-e5c0-4ddf-80ea-43d383f5e58e',
  742. '9b7aa0c9-6393-4337-95cd-2bf0c57a662c',
  743. '93811e7f-fa3f-4487-9310-ef28ba3530f4',
  744. '43ecedc4-45fa-4ab7-b87b-357be07b19fa',
  745. 'a7fa4f17-9a9e-4d0b-bca7-2edfdcd75afb',
  746. '3682bc09-96ab-4d17-9010-b9fc31dc72bd',
  747. '04eff65e-3e19-4b57-b3ba-f1f63f52b8ba',
  748. '9eaea71a-97c8-456d-afc4-97d00e2e83bd',
  749. 'e3d846fd-c9e7-44b1-966d-ba74b4953f54',
  750. '2db6561b-3657-418a-ba18-b726a86d1fb1',
  751. '93b32d4b-a918-4940-bcef-00fbeceff525',
  752. '18e6f96a-c4d3-4cca-9248-f7c9099c6706',
  753. '3e1866ed-c9d0-415f-a080-ed1b34704110',
  754. 'd4ee5661-646b-4a58-b2b8-ad309666d64e',
  755. 'b678edb6-4717-423f-a8ac-6abc80eeab97',
  756. 'e8d68e11-d1e9-4bc7-8e22-e426f50f70a2',
  757. '8e96efbd-b990-4e2e-ad43-49e9dae73794',
  758. '72793b29-c939-4201-82b8-7ded1e6c6fe5',
  759. '59b5a6bc-ae2a-4157-b262-bf7a4858aace',
  760. 'e6b642ef-4239-4063-b471-da5b987b6aeb',
  761. 'f5ebf426-b4bc-4744-a2f3-a35a22c6c326',
  762. 'a7e80ecb-2a53-4879-a0f4-d313f78d3c01',
  763. 'cf32535a-b754-4cee-a51d-be4dc2220a2f',
  764. '521c66d6-00cc-4ec6-b391-0d9ce1995c42',
  765. '523b17d0-629f-44de-8f24-0c3915493fb0',
  766. '771b45c4-dde0-4d6a-ba69-6d8f537e4c1f',
  767. 'f9b374fd-1af4-4623-b117-c75fa4e7f4f8',
  768. '479f343e-51b7-49bd-8ebb-cb81af8ae7b0',
  769. 'cc992aae-2942-4836-9351-cedbd1cc4e61',
  770. '3f5d1192-4c56-43a6-9140-18043d6c41e5',
  771. 'dffad9b6-f3f2-4470-be45-94c81af04a02',
  772. '39289aa9-2506-4d04-866e-e6eec9b4d9db',
  773. '243299ec-6a98-43ac-b3db-272f5abbbd78',
  774. '9f715766-ef6a-479d-895d-945952a8ff6e',
  775. '2ff9bd86-8621-4f04-b560-abff5a202232',
  776. '75da24ed-8196-4eb1-8413-3916d7b271a3',
  777. '6adc96f3-c6e5-4a8d-a33f-5bbcbb92b296',
  778. '0b2dcfbc-d334-4032-b354-f6fa98a57d99',
  779. 'e2110a26-3af6-4c53-8b38-51ed4b415d48',
  780. '85e4c259-f531-43dd-a2b8-76cb750f8604',
  781. '1a6731a3-cc57-4463-84e1-bca0917c2399',
  782. 'd574dac8-4440-48f0-af37-b982db545ea3',
  783. '753ca661-d930-4f33-bce3-5385c310744f',
  784. 'e70800f3-836b-43e9-aa8c-c5e789d7054e',
  785. '32a94a0c-c14c-4208-8bd1-0d84c69d690e',
  786. 'f5d242b3-db25-4877-8a63-4d4dcf8f8f2c',
  787. '87399fcb-34fb-494b-b74f-02979a665dc0',
  788. '85796371-1079-4fff-947d-671720377e72',
  789. '40f04a01-e373-430a-a1f5-cbb8fbcff4cb',
  790. '6e6a3d09-c65d-4996-bd96-035f5d19e634',
  791. 'd340ea8f-e869-46d5-8813-5cce7991edea',
  792. '8a72592b-09fb-4910-b4e9-c76ef039b44f',
  793. '740b8b24-c7f5-4df5-a13a-92a1c37619bc',
  794. 'c19ef79f-d3f3-4125-8e1a-83cee110e03b',
  795. '1894992c-2575-4949-971d-c84669fcfd06',
  796. '4d51ace2-9f18-4f01-be7b-1ab4694e62dd',
  797. 'c1564967-890f-49e2-983a-933df4cbf8d0',
  798. 'aff088da-91e6-400a-ab84-c6cf300b361f',
  799. 'b0557e5e-41c5-4273-b793-dcb8a0613e6f',
  800. 'd0317e30-bcc4-4b03-9417-4dba3a216105',
  801. '86a28ef8-f3fc-44ef-942b-a9a658bb0731',
  802. '53623415-70e8-44f6-9ea6-bd709e40984c',
  803. '9ee23eee-850c-4cb0-8147-829ae0502705',
  804. 'd6fbfc1e-6093-4e70-8432-453246c80eb3',
  805. 'ac0e96dd-ec15-4b39-834d-1000ac3aa4c4',
  806. '1e8c9744-8054-405b-997c-de13e58967a4',
  807. 'c87c282c-6a83-40d1-86bc-af3045c0c41a',
  808. '4c221226-f490-4657-bd98-cf24bba48d7e',
  809. 'fd218bdd-7c18-41d6-a592-59a4c3ee98fe',
  810. '0c916db0-f7fa-4abc-a548-ca81cb416e59',
  811. '9f3c9615-3066-45d8-99a9-eacc8f6d692d',
  812. '6ed5074e-c7df-49f1-84c8-bb6276db9d1d',
  813. 'c2eb2c78-60d3-4616-9215-5ca810c58e4d',
  814. '4aef197d-5c62-4bce-aab2-804c87db5b28',
  815. '3231a06f-118a-437f-b863-4ffcba56d03a',
  816. 'a827a795-f86e-46eb-8369-f63b061d87d9',
  817. 'd4fd8c14-81d1-41b3-b652-f1dfb107d0d6',
  818. 'a0f2b207-0ef7-4ca4-b595-12f46b4b8434',
  819. '115f8e21-ebdb-4241-9c34-91fbef1b6fb9',
  820. '34c8923a-0230-448a-9d06-a8f2922520a3',
  821. '04803687-4689-45a6-b19e-4d3a39ccc348',
  822. '8bb657c9-7638-4ab9-af92-a4370d53960e',
  823. '1e766445-9971-4358-86be-fba295460866',
  824. '367c0575-b150-44eb-b447-5468d4d833fe',
  825. '2a379010-1f57-43f7-8f99-1f254ad93c26',
  826. '496adcc6-2897-4f16-9e9b-75fbcfd313a0',
  827. 'c32a4e86-637f-4c68-8824-2d4370eea5ee',
  828. 'b03b9f85-6d51-4c9c-a354-22bd3aa67462',
  829. '829a1242-f1e0-4154-aacf-362c021172f2',
  830. '4a451d51-b96c-4740-9018-7d22bbd842cf',
  831. '497a3b9a-55da-4991-af53-657c04edd0b3',
  832. 'b89b915f-f4ea-44f6-ae3a-e45af1942022',
  833. '781c4777-a869-4857-b052-71cbecbf6e35',
  834. '16a1d9aa-4bba-4c6f-86e5-7f7a281e7cd2',
  835. 'a5125445-cd2c-44b1-af19-addd25b8eeef',
  836. '81f574b9-9da2-43ae-ac6c-54ceb637c1fa',
  837. '1d469b5a-386c-4ace-9477-826c2d9d2b5d',
  838. '4fb0c252-5df1-44f9-a6e4-40078740a4e8',
  839. '1d7574e8-cf7c-460f-aad9-b4eec908121c',
  840. 'b0d23d24-a66f-4fb7-badc-980bebe0118d',
  841. 'e9570402-e4db-4a7c-9d5c-c5f95ad8ed0a',
  842. 'b08a57bc-6f1a-491c-a126-490ad5c8f90c',
  843. '583f3908-5caf-4703-84c6-e32cbbafca1e',
  844. '271cf872-cc61-493d-a595-be644bb2e098',
  845. 'a031cf56-0aa1-40c1-a325-14f6f1204cad',
  846. '3f492d1f-d95d-4947-8944-1e47fbe6abb4',
  847. '44d282b7-413f-4f1a-b5cf-5b9b81acbb6a',
  848. 'cef3a415-dc3f-4143-b905-5b1bac1b10c9',
  849. '37fe497b-1ba6-46e7-a9b9-fd70993b9753',
  850. 'c0db0c30-590c-42bd-bac7-d065a05843cd',
  851. '19532426-9ee6-4cc0-8d7b-7c5753b95b64',
  852. '7421dcb4-14d3-4656-9257-a2b287ff41a8',
  853. 'bd5805f7-a7eb-4189-8e48-9b3978d22362',
  854. '012861ec-8bbb-42e2-9e39-349a5b172c21',
  855. '731daff9-ccf2-48d3-88bc-ff02ec7ff2f9',
  856. '5b47d6c3-df81-4456-a165-4af6ee34c375',
  857. '2129126a-838f-4e3d-a8a4-1bf9e8d70ce8',
  858. 'acb84287-1cf7-4aa5-8892-e92beb6f6871',
  859. 'b2d337e4-16b4-459d-9d7f-922458e2671c',
  860. 'c63b9cd7-bce4-4c80-91c2-c305916d3d22',
  861. '1a7d052b-97b6-40ab-9b45-3e163710ea10',
  862. 'bd096e5e-0dc3-4b2e-9e4a-ffc3ac2a8e8b',
  863. '1afbab3e-193c-408c-b024-3365730d1698',
  864. '6e268ebe-aa65-4fa0-8fc1-877d0688cf8d',
  865. '89675ae3-9773-4b37-bc69-6a926f608b0e',
  866. 'd96a0716-89e1-4b5b-b02a-0cb438bd4933',
  867. '693e024a-1b71-4c9e-868e-ad9524728988',
  868. '5fb1ad4b-7a79-4a55-b627-3d1354a22754',
  869. 'c050b6d6-5f1a-4f3f-9385-521d9f992f11',
  870. '62051b3d-1a64-4509-914c-a382f573c050',
  871. '8b6c6a22-3a4c-48f4-bba4-57db1af2ec2e',
  872. 'ca5d3896-35ad-4848-ad2a-beb04263999d',
  873. '1bac6904-2f36-45f5-9e8e-894e28a5674d',
  874. '89f1a5f6-3c29-4338-8a00-5645dbaa80ad',
  875. 'def9d072-fee5-44f6-bc18-5b2750d4efc5',
  876. '032e2e84-6154-49ee-8d4d-e3b3b631595b',
  877. '6cb4e7ba-9be8-4c8a-bf4a-437faf96c084',
  878. 'd6df2ed5-8963-42c0-8832-537a210e900e',
  879. 'ec647fea-a650-4b18-b267-3f8d9d104c23',
  880. '10374436-b76b-4d73-853e-abe12b8f0079',
  881. '8b87190e-3fd1-40d3-9a7f-efb986cd7fa5',
  882. '30803959-1b88-4b8a-8716-d74e58f2eacd',
  883. 'b7c69c8d-b4c0-4523-ac73-f9629d2b5c37',
  884. 'da21dd7d-fe43-474f-bcd0-e2819b71ab40',
  885. 'ae97438f-afc8-4f01-90da-da5fbbc7b759',
  886. '95920cea-040e-40a0-a9fa-ea7e48945e5e',
  887. 'bf0ec2c2-b1b5-41a4-990b-ebd32e64bcc5',
  888. '06add3e9-8566-44b0-8962-6f1377410b48',
  889. '1a56021a-b4e5-45e0-83e5-7ec707097271',
  890. 'd35c54ea-3985-484f-9a3a-abc4be8fc774',
  891. 'a7c3bd26-ac43-4a61-99fe-428ea141a826',
  892. '414a46cb-4e88-4217-adfd-395f3f4cb12c',
  893. '241729ee-cfe7-4ee2-868e-3f617fd62bba',
  894. 'c05c28db-8b03-4d0c-8a37-c0e36c6fd0e8',
  895. '5b72fe37-3bc6-4563-9a1e-bfd62b692980',
  896. '73609b0e-1bc7-4c64-a39e-df52a34a5325',
  897. '477bba0c-d64f-4543-90eb-481183874bf8',
  898. 'd2d5be63-6e49-46d5-ae96-3b106b907902',
  899. '9091e31c-28c6-4a31-9958-36d0875ef8d7',
  900. '4fedd41a-d3d2-475d-8804-8c716ac4e160',
  901. '5d322e5c-ad86-42b2-a20d-1fa0e3279361',
  902. '99297e99-3b10-4353-a691-02492f2b88d1',
  903. '5b1206de-1b99-4b96-8e98-5c85ca630cea',
  904. '65d501e8-4663-4ae8-a07e-59b30b75a645',
  905. 'b53311e3-5276-45d6-87a1-36bf28b653be',
  906. '6bd75463-1dec-4001-ab24-cd2e07986759',
  907. '9b3201a9-ce44-41a7-8ad5-6769f726c2d0',
  908. '0acf8a5d-0feb-4497-9a0a-e95f86138157',
  909. '522597e8-bada-4c5b-bdf2-06af764a4bfe',
  910. '1fca91fb-3e03-438e-8f1b-a9b77b14634c',
  911. 'c8bd6ef8-ff2e-40c5-8f15-973caea0ed58',
  912. 'ba318882-7eeb-42a0-bfcb-09ac71fc0046',
  913. '0e1d09bd-f176-4e21-9f55-b821703a7b24',
  914. '3f58f289-a206-4fbd-93c6-0752d3d0a250',
  915. 'fd23121d-959d-443c-ac22-4cf7cac3751c',
  916. 'd3b4384a-290e-4cb0-bfda-b34097d5ca72',
  917. '2d7b5467-0e74-40ae-ab21-bf29ee3fe02c',
  918. 'd3db6faa-4b07-460a-bcbd-48dcc109fbc4',
  919. 'e5d14fe7-a5a0-4610-b1b7-87c9d936c7ff',
  920. 'f386b6f5-1fd2-4a2e-8ec0-6762ddd5c477',
  921. '60c09883-dff1-49ee-bafb-1991aab238aa',
  922. '6664e420-91ad-4c89-9955-313b163f722e',
  923. 'b81724c3-c045-436b-9d55-f528918de742',
  924. '5de09e10-e4bd-4df2-8628-9e432b17ec65',
  925. 'af93606e-5dbc-4401-99e6-adea66903418',
  926. 'fe7998e5-0a31-45a8-aab0-1867092d855c',
  927. 'd64bdffe-8388-4a9c-a3f9-bbd1b75ea224',
  928. 'c8845227-73ea-45fe-920c-be3e166b04c3',
  929. '6087c06a-10fc-4c92-adb3-95f85423fe2e',
  930. '6c64f697-21cf-4d58-8810-d0306e0c5dc4',
  931. 'bc2ee64e-cb01-4101-9d2d-fd37f31fd881',
  932. 'c076b996-1f81-4f4a-8c04-a1a69348863f',
  933. 'f2fab9c5-2a57-4f0a-8b48-000fc08eec98',
  934. 'b496b620-713e-4312-8d80-4f89d10187de',
  935. '6995deff-b9e8-479b-84fc-d981efab4d3b',
  936. 'cd7e8c81-231f-42ab-a30d-7665e9097a71',
  937. '38452e41-1ec3-40ca-ac3a-2579e47e5f16',
  938. '16e904e2-b77b-4723-86ee-ba85a9d3762f',
  939. '9e5e308a-c291-4feb-a225-336f0f949489',
  940. '8391694a-dccb-48eb-8d3b-56401e5fb030',
  941. 'f210dd0a-e288-477a-9a16-d622cc92a818',
  942. '17908451-473c-4fd8-848c-23ef7846fa43',
  943. 'cea1ec2e-02e6-4777-b931-b2042b3f1230',
  944. '70fd95b8-be8c-4545-a46f-6c050449a822',
  945. '057d4f31-3338-4d7b-869c-98fcb114153d',
  946. '8d032ab5-c7db-4ceb-9a37-f55f8a59416c',
  947. '5e8a8ffe-73ac-4a29-9bcc-a03c06b25b2e',
  948. '55fd11e2-047f-4acf-9533-22023684dd58',
  949. '45a4b0c1-dbbf-423e-b287-d44c71089f69',
  950. 'c52cd0d3-4385-4efb-8f33-f947564a70cb',
  951. '07d593c2-9ad7-4ae5-b471-b3e2622c940b',
  952. 'adf77ae2-63f7-4732-82d0-29d434f83445',
  953. 'bdee46ba-fab6-485d-ad89-fda5578859cc',
  954. 'f8b9bccc-1c4f-433d-9917-f4ad007f7105',
  955. '7d2bd01e-5435-4dbd-8e9b-897e777691f6',
  956. '56cacfd9-aeef-4477-abb9-2a22e0a92ae7',
  957. '891c7363-60c7-4aa5-846e-e7e3913e37d4',
  958. '376c26d3-8ebc-4c10-a5c1-aef9606318a8',
  959. '3efc8c68-3cee-4bc6-bdcd-ffc4c1a3437b',
  960. '1a7e5fda-eb4c-4f62-ad2d-b3e04e0e725a',
  961. 'dd4b0cd7-73d4-46fa-bf19-12e35f64be43',
  962. 'ccf206a1-fcc8-4552-b12f-ebed670cff73',
  963. 'c275d71f-cdb3-443c-82ab-821dd80500ea',
  964. 'e269c78b-2b0c-4fd1-bc0f-2ff671151030',
  965. '41e4371e-7495-4008-9951-7b3ab843429e',
  966. 'c54ac4b5-9267-4087-b724-6b0d44713162',
  967. 'e43fb790-aa3f-4209-838d-d830a9c5fd53',
  968. '982f3d88-bfe1-46c8-ac95-7adbd06a98f1',
  969. '8ded07a1-1dda-4dea-8e0d-05475693642c',
  970. 'edb7d6b2-4d86-486f-b4b6-bac71fe6c460',
  971. 'c3416899-550b-4e1a-93f5-690dcf67cd6b',
  972. '89a915cf-aee4-4472-91e6-7f33d5ef490b',
  973. 'c3587e4c-020a-4bef-8ad5-bcbb9a7ea485',
  974. '91e8d5b4-8b73-470b-b900-7cd8f5508e82'
  975. )";
  976. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).GetItemQueryIteratorSql<StudentArtResult>(sql))
  977. {
  978. art_idNames.Add(item);
  979. }
  980. List<dynamic> unfinish = new List<dynamic>();
  981. ConcurrentDictionary<string, int> schoolFinish = new ConcurrentDictionary<string, int>();
  982. ConcurrentDictionary<string, int> schoolUnFinish = new ConcurrentDictionary<string, int>();
  983. List<Class> classes = new List<Class>();
  984. foreach (var z in art_idNames)
  985. {
  986. var data = z.results.Where(x => (x.subjectId.Equals("subject_painting") && x.quotaId.Equals("quota_21") && x.score == -1)
  987. || (x.subjectId.Equals("subject_music") && x.quotaId.Equals("quota_21") && x.score == -1)
  988. || (x.subjectId.Equals("subject_music") && x.quotaId.Equals("quota_22") && x.score == -1)
  989. || (x.subjectId.Equals("subject_painting") && x.quotaId.Equals("quota_22") && x.files.IsEmpty())
  990. );
  991. if (data.Any())
  992. {
  993. var p21 = z.results.FindAll(x => x.subjectId.Equals("subject_painting") && x.quotaId.Equals("quota_21"))?.First();
  994. var p22 = z.results.FindAll(x => x.subjectId.Equals("subject_painting") && x.quotaId.Equals("quota_22"))?.First();
  995. int p22source = 0, p21source = 0, m21source = 0, m22source = 0;
  996. if (p21.score > -1)
  997. {
  998. p21source = 1;
  999. }
  1000. if (p22.files.IsNotEmpty())
  1001. {
  1002. p22source = p22.files.Count;
  1003. }
  1004. var m21 = z.results.FindAll(x => x.subjectId.Equals("subject_music") && x.quotaId.Equals("quota_21"))?.First();
  1005. if (m21.score > -1)
  1006. {
  1007. m21source = 1;
  1008. }
  1009. var m22 = z.results.FindAll(x => x.subjectId.Equals("subject_music") && x.quotaId.Equals("quota_22"))?.First();
  1010. if (m22.score > -1)
  1011. {
  1012. m22source = 1;
  1013. }
  1014. string className = "";
  1015. string periodName = "";
  1016. string schoolName = "";
  1017. School school = schools.Find(a => a.id.Equals(z.school));
  1018. schoolName = school?.name;
  1019. if (!string.IsNullOrWhiteSpace(z.classIds?.First()))
  1020. {
  1021. var clasz = classes.Find(x => x.id.Equals(z.classIds?.First()));
  1022. if (clasz == null)
  1023. {
  1024. clasz = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<Class>(z.classIds.First(), new PartitionKey($"Class-{z.school}"));
  1025. classes.Add(clasz);
  1026. }
  1027. className = clasz?.name;
  1028. var period = school?.period?.Where(m => m.id.Equals(clasz.periodId));
  1029. if (period.Any())
  1030. {
  1031. periodName = period.First().name + "-" + period.First().periodType;
  1032. }
  1033. }
  1034. unfinish.Add(new { z.school, schoolName = schoolName, z.studentId, z.studentName, z.artId, periodName, classname = className, p21source, p22source, m21source, m22source, taskId = m22?.taskId });
  1035. if (schoolUnFinish.ContainsKey(schoolName))
  1036. {
  1037. schoolUnFinish[schoolName]++;
  1038. }
  1039. else { schoolUnFinish.TryAdd(schoolName, 1); }
  1040. }
  1041. else
  1042. {
  1043. School school = schools.Find(a => a.id.Equals(z.school));
  1044. string schoolName = school?.name;
  1045. if (schoolFinish.ContainsKey(schoolName))
  1046. {
  1047. schoolFinish[schoolName]++;
  1048. }
  1049. else { schoolFinish.TryAdd(schoolName, 1); }
  1050. }
  1051. }
  1052. return Ok(new { unfinish, schoolFinish , schoolUnFinish });
  1053. }
  1054. [ProducesDefaultResponseType]
  1055. [HttpPost("check-ems")]
  1056. public async Task<IActionResult> CheckPjx(JsonElement json)
  1057. {
  1058. var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
  1059. int itemId = 0;
  1060. if (json.TryGetProperty("itemId", out JsonElement _itemId)) {
  1061. itemId= _itemId.GetInt32();
  1062. }
  1063. List< ScTeacher > teachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", "ScTeacher" }, { "ProjectItemID", itemId } });
  1064. List<dynamic> unbind = new List<dynamic>();
  1065. List<dynamic> unupload_rzcl = new List<dynamic>();
  1066. List<dynamic> uploads_rzcl = new List<dynamic>();
  1067. List<dynamic> unupload_video = new List<dynamic>();
  1068. List<dynamic> uploads_video = new List<dynamic>();
  1069. foreach (var teacher in teachers)
  1070. {
  1071. if (!string.IsNullOrWhiteSpace(teacher.schoolCode) && !string.IsNullOrWhiteSpace(teacher.tmdid))
  1072. {
  1073. int upcont = 0;
  1074. string sql = "select value c from c where c.currency=1";
  1075. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
  1076. .GetItemQueryIteratorSql<AbilitySub>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilitySub-{teacher.schoolCode}-{teacher.tmdid}") }))
  1077. {
  1078. if (item.uploads.IsNotEmpty())
  1079. {
  1080. upcont++;
  1081. uploads_rzcl.Add(new { teacher.TeacherName,teacher.SchoolName,teacher.PXID,time= DateTimeOffset.FromUnixTimeMilliseconds(item.uploads.OrderByDescending(m => m.time).FirstOrDefault().time).ToString("yyyy-MM-dd HH:mm:ss"), teacher?.tmdid });
  1082. }
  1083. }
  1084. if(upcont<3)
  1085. {
  1086. unupload_rzcl.Add(new { teacher.TeacherName, teacher.SchoolName, teacher.PXID ,teacher?.tmdid});
  1087. }
  1088. string sql_video =$"select value c from c where c.id='{teacher.tmdid}'";
  1089. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
  1090. .GetItemQueryIteratorSql<ClassVideo>(queryText: sql_video, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"ClassVideo-{teacher.schoolCode}") }))
  1091. {
  1092. if (item.files.IsNotEmpty())
  1093. {
  1094. uploads_video.Add(new { teacher.TeacherName, teacher.SchoolName, teacher.PXID, time = DateTimeOffset.FromUnixTimeMilliseconds(item.files.OrderByDescending(m => m.time).FirstOrDefault().time).ToString("yyyy-MM-dd HH:mm:ss"), teacher?.tmdid });
  1095. }
  1096. else
  1097. {
  1098. unupload_video.Add(new { teacher.TeacherName, teacher.SchoolName, teacher.PXID, teacher?.tmdid });
  1099. }
  1100. }
  1101. }
  1102. else {
  1103. unbind.Add(new { teacher.TeacherName,teacher.SchoolName,teacher.PXID});
  1104. }
  1105. }
  1106. Dictionary<string, object> dict = new Dictionary<string, object>();
  1107. var tchs= teachers.GroupBy(z => z.areaId).Select(b => new { areaId = b.Key, schools = b.Select(v=>v.schoolCode).ToHashSet(), pushTeachers = b.Where(c=>!string.IsNullOrWhiteSpace(c.tmdid)).Select(d=>d.tmdid)});
  1108. return Ok(new { unbind , unupload_rzcl, uploads_rzcl, uploads_video, unupload_video , tchs });
  1109. }
  1110. [ProducesDefaultResponseType]
  1111. [HttpPost("sendmsg")]
  1112. public async Task<IActionResult> Sendmsg(JsonElement json)
  1113. {
  1114. byte[] bytes = Encoding.UTF8.GetBytes(json.GetRawText());
  1115. var memoryStream = new MemoryStream(bytes);
  1116. ResponseMessage res = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).CreateItemStreamAsync(memoryStream, new PartitionKey("Base12"));
  1117. if (res.StatusCode == HttpStatusCode.Created)
  1118. {
  1119. return Ok(201);
  1120. }
  1121. //var messageBlobPDF = new ServiceBusMessage(new { userType = "tmdid", bizType = "OfflineRecord" }.ToJsonString());
  1122. //await _serviceBus.GetServiceBusClient().SendMessageAsync("screenpdf", messageBlobPDF);
  1123. return Ok();
  1124. }
  1125. [ProducesDefaultResponseType]
  1126. [HttpPost("get-subTime")]
  1127. public async Task<IActionResult> GetSubTime(JsonElement request) {
  1128. if (!request.TryGetProperty("ids", out JsonElement id)) return BadRequest();
  1129. List<string> ids = id.ToObject<List<string>>();
  1130. var queryClass = $"select c.time from c ";
  1131. var client = _azureCosmos.GetCosmosClient();
  1132. List<(string td, long tt)> ht = new();
  1133. foreach (string tmdId in ids) {
  1134. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIteratorSql(queryText: queryClass,
  1135. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"HomeworkRecord-{tmdId}") }))
  1136. {
  1137. using var json = await JsonDocument.ParseAsync(item.Content);
  1138. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  1139. {
  1140. var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
  1141. while (accounts.MoveNext())
  1142. {
  1143. JsonElement account = accounts.Current;
  1144. account.TryGetProperty("time", out JsonElement time);
  1145. ht.Add((tmdId,time.GetInt64()));
  1146. }
  1147. }
  1148. }
  1149. }
  1150. var home = ht.Select(x => new
  1151. {
  1152. id = x.td,
  1153. time = DateTimeOffset.FromUnixTimeMilliseconds(x.tt).ToString("yyyy-MM-dd HH:mm")
  1154. //time = DateTimeHelper.FromUnixTimestampOffSet(x.tt,8).ToString("yyyy-MM-dd HH:mm")
  1155. });
  1156. return Ok(home);
  1157. }
  1158. [ProducesDefaultResponseType]
  1159. [HttpPost("get-semester")]
  1160. public async Task<IActionResult> GetSemester(JsonElement json)
  1161. {
  1162. List<Semester> semesterList = new List<Semester>();
  1163. semesterList.Add(
  1164. new Semester
  1165. {
  1166. id = Guid.NewGuid().ToString(),
  1167. name = "第二学期",
  1168. start = 0,
  1169. month = 3,
  1170. day = 1
  1171. });
  1172. semesterList.Add(
  1173. new Semester
  1174. {
  1175. id = Guid.NewGuid().ToString(),
  1176. name = "第一学期",
  1177. start = 1,
  1178. month = 9,
  1179. day = 1
  1180. });
  1181. //semesterList.Add(
  1182. // new Semester
  1183. // {
  1184. // id = "q",
  1185. // name = "第四学期",
  1186. // start = 0,
  1187. // month = 7,
  1188. // day = 1
  1189. // });
  1190. //semesterList.Add(
  1191. // new Semester
  1192. // {
  1193. // id = "q",
  1194. // name = "第三学期",
  1195. // start = 0,
  1196. // month = 4,
  1197. // day = 1
  1198. // });
  1199. semesterList = SortSemester(semesterList);
  1200. return Ok(semesterList);
  1201. }
  1202. private List<Semester> SortSemester(List<Semester> semesterList)
  1203. {
  1204. int Year = DateTimeOffset.UtcNow.Year;
  1205. List<KeyValuePair<int, Semester>> pairs = new List<KeyValuePair<int, Semester>>();
  1206. semesterList.ForEach(se => {
  1207. string sm = se.month >= 10 ? $"{se.month}" : $"0{se.month}";
  1208. string sd = se.day >= 10 ? $"{se.day}" : $"0{se.day}";
  1209. int order = int.Parse($"{Year}{sm}{sd}");
  1210. pairs.Add(new KeyValuePair<int, Semester>(order, se));
  1211. });
  1212. var orderPairs = pairs.OrderBy(z => z.Key);
  1213. semesterList = orderPairs.Select(z => z.Value).ToList();
  1214. int startIndex = semesterList.FindIndex(z => z.start == 1);
  1215. if (startIndex == -1)
  1216. {
  1217. //未设置学期的情况默认9月份开始的。
  1218. startIndex = semesterList.FindIndex(z => z.month == 9);
  1219. //如果还未找到,就以排序结果为准
  1220. if (startIndex == -1)
  1221. {
  1222. startIndex = 0;
  1223. }
  1224. }
  1225. if (startIndex > 0)
  1226. {
  1227. List<Semester> before = semesterList.Take(startIndex).ToList();
  1228. List<Semester> after = semesterList.Skip(startIndex).ToList();
  1229. semesterList = new List<Semester>();
  1230. semesterList.AddRange(after);
  1231. semesterList.AddRange(before);
  1232. return semesterList;
  1233. }
  1234. else
  1235. {
  1236. return semesterList;
  1237. }
  1238. }
  1239. /*
  1240. [
  1241. {"method":"台北市","params":{"CountryId":"TW","CityId":"30"}},1
  1242. {"method":"新北市","params":{"CountryId":"TW","CityId":"01"}},1
  1243. {"method":"桃园市","params":{"CountryId":"TW","CityId":"03"}},1
  1244. {"method":"台中市","params":{"CountryId":"TW","CityId":"66"}},1
  1245. {"method":"台南市","params":{"CountryId":"TW","CityId":"67"}},1
  1246. {"method":"高雄市","params":{"CountryId":"TW","CityId":"64"}},1
  1247. {"method":"基隆市","params":{"CountryId":"TW","CityId":"17"}},1
  1248. {"method":"新竹市","params":{"CountryId":"TW","CityId":"18"}},1
  1249. {"method":"嘉义市","params":{"CountryId":"TW","CityId":"20"}},1
  1250. {"method":"新竹县","params":{"CountryId":"TW","CityId":"04"}},1
  1251. {"method":"苗栗县","params":{"CountryId":"TW","CityId":"05"}},1
  1252. {"method":"彰化县","params":{"CountryId":"TW","CityId":"07"}},1
  1253. {"method":"南投县","params":{"CountryId":"TW","CityId":"08"}},1
  1254. {"method":"云林县","params":{"CountryId":"TW","CityId":"09"}},1
  1255. {"method":"嘉义县","params":{"CountryId":"TW","CityId":"10"}},1
  1256. {"method":"屏东县","params":{"CountryId":"TW","CityId":"13"}},1
  1257. {"method":"宜兰县","params":{"CountryId":"TW","CityId":"02"}},1
  1258. {"method":"花莲县","params":{"CountryId":"TW","CityId":"15"}},1
  1259. {"method":"台东县","params":{"CountryId":"TW","CityId":"14"}},1
  1260. {"method":"澎湖县","params":{"CountryId":"TW","CityId":"16"}},1
  1261. {"method":"金门县","params":{"CountryId":"TW","CityId":"71"}},
  1262. {"method":"连江县","params":{"CountryId":"TW","CityId":"72"}}
  1263. ]
  1264. */
  1265. /// <summary>
  1266. /// 测试blob多线程写入同一个文件
  1267. /// </summary>
  1268. /// <returns></returns>
  1269. [ProducesDefaultResponseType]
  1270. [HttpPost("get-schools")]
  1271. public async Task<IActionResult> GetSchools(JsonElement json)
  1272. {
  1273. string msg = "{\"standard\":\"standard3\",\"tmdids\":[\"1635136038\"],\"school\":\"pbjyey\",\"update\":[\"TeacherAbility\"],\"statistics\":0}";
  1274. try
  1275. {
  1276. TeacherTrainChange change = msg.ToObject<TeacherTrainChange>();
  1277. var client = _azureCosmos.GetCosmosClient();
  1278. string insql = $"where c.id in ({string.Join(",", change.tmdids.Select(x => $"'{x}'"))})";
  1279. string selsql = $"select value(c) from c {insql} ";
  1280. List<TeacherTrain> teacherTrains = new List<TeacherTrain>();
  1281. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIteratorSql<TeacherTrain>(queryText: selsql,
  1282. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"TeacherTrain-{change.school}") }))
  1283. {
  1284. teacherTrains.Add(item);
  1285. }
  1286. if (change.statistics != 1)
  1287. {
  1288. List<Task<ItemResponse<TeacherTrain>>> task = new List<Task<ItemResponse<TeacherTrain>>>();
  1289. teacherTrains.ForEach(x =>
  1290. {
  1291. x.update.UnionWith(change.update);
  1292. task.Add(client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<TeacherTrain>(x, x.id, new PartitionKey($"TeacherTrain-{change.school}")));
  1293. });
  1294. await task.TaskPage(5);
  1295. var unchange = change.tmdids.Except(teacherTrains.Select(x => x.id));
  1296. if (unchange != null)
  1297. {
  1298. task.Clear();
  1299. unchange.ToList().ForEach(x =>
  1300. {
  1301. TeacherTrain teacherTrain = new TeacherTrain
  1302. {
  1303. pk = "TeacherTrain",
  1304. id = x,
  1305. code = $"TeacherTrain-{change.school}",
  1306. tmdid = x,
  1307. school = change.school,
  1308. update = new HashSet<string> { StatisticsService.TeacherAbility,
  1309. StatisticsService.TeacherClass, StatisticsService.OfflineRecord }
  1310. };
  1311. teacherTrain.update.UnionWith(change.update);
  1312. task.Add(client.GetContainer(Constant.TEAMModelOS, "Teacher").UpsertItemAsync<TeacherTrain>(teacherTrain, new PartitionKey($"TeacherTrain-{change.school}")));
  1313. });
  1314. await task.TaskPage(1);
  1315. }
  1316. }
  1317. else
  1318. {
  1319. Area area = null;
  1320. string sql = $"select value(c) from c where c.standard='{change.standard}'";
  1321. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIteratorSql<Area>(queryText: sql,
  1322. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-Area") }))
  1323. {
  1324. area = item;
  1325. }
  1326. AreaSetting setting = null;
  1327. if (area != null)
  1328. {
  1329. try
  1330. {
  1331. //优先找校级
  1332. setting = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<AreaSetting>(change.school, new PartitionKey("AreaSetting"));
  1333. }
  1334. catch (CosmosException)
  1335. {
  1336. try
  1337. {
  1338. setting = await client.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<AreaSetting>(area.id, new PartitionKey("AreaSetting"));
  1339. }
  1340. catch (CosmosException)
  1341. {
  1342. setting = null;
  1343. }
  1344. }
  1345. }
  1346. if (setting == null)
  1347. {
  1348. setting = new AreaSetting
  1349. {
  1350. allTime = 50,
  1351. classTime = 5,
  1352. submitTime = 15,
  1353. onlineTime = 20,
  1354. offlineTime = 10,
  1355. lessonMinutes = 45,
  1356. };
  1357. }
  1358. List<Task<TeacherTrain>> task = new List<Task<TeacherTrain>>();
  1359. teacherTrains.ForEach(x =>
  1360. {
  1361. x.update.UnionWith(change.update);
  1362. task.Add(StatisticsService.StatisticsTeacher(x, setting, area, client, null));
  1363. });
  1364. await task.TaskPage(1);
  1365. var unchange = change.tmdids.Except(teacherTrains.Select(x => x.id));
  1366. if (unchange != null)
  1367. {
  1368. task.Clear();
  1369. unchange.ToList().ForEach(x =>
  1370. {
  1371. task.Add(StatisticsService.StatisticsTeacher(new TeacherTrain
  1372. {
  1373. pk = "TeacherTrain",
  1374. id = x,
  1375. code = $"TeacherTrain-{change.school}",
  1376. tmdid = x,
  1377. school = change.school,
  1378. update = new HashSet<string> { StatisticsService.TeacherAbility,
  1379. StatisticsService.TeacherClass, StatisticsService.OfflineRecord }
  1380. }, setting, area, client, null));
  1381. });
  1382. await task.TaskPage(1);
  1383. }
  1384. }
  1385. }
  1386. catch (CosmosException ex)
  1387. {
  1388. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-研修数据变更,重新统计-TeacherTrainChange\n{msg}\n{ex.Message}\n{ex.StackTrace}\nCosmosException{ex.StatusCode}", GroupNames.醍摩豆服務運維群組);
  1389. }
  1390. catch (Exception ex)
  1391. {
  1392. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-研修数据变更,重新统计-TeacherTrainChange\n{msg}\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1393. }
  1394. /*
  1395. string path = $"{_environment.ContentRootPath}/JsonFile/Core/city.json";
  1396. StreamReader streamReader = new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8);
  1397. StringBuilder stringBuilder = new StringBuilder();
  1398. string text;
  1399. while ((text = streamReader.ReadLine()) != null)
  1400. {
  1401. stringBuilder.Append(text.ToString());
  1402. }
  1403. streamReader.Close();
  1404. string input = stringBuilder.ToString();
  1405. List<string> region = new List<string>() {
  1406. "110000", "110100", "110200",
  1407. "120000", "120100", "120200",
  1408. "310000", "310100", "310200",
  1409. "500000", "500100", "810100",
  1410. "810200", "810300", "820100",
  1411. "820200", "820300"
  1412. };
  1413. List<string> cityids = new List<string>() {
  1414. "30","01","03","66","67","64","17","18","20","04","05","07","08","09","10","13","02","15","14","16","71","72"
  1415. };
  1416. Dictionary<string, List<CodeName>> regions = input.ToObject<Dictionary<string, List<CodeName>>>();
  1417. List<List<string>> datas = new List<List<string>>() { region };
  1418. foreach (var r in regions)
  1419. {
  1420. if (!region.Contains(r.Key) && !r.Key.StartsWith("71"))
  1421. {
  1422. datas.Add(r.Value.Select(x => x.code).ToList());
  1423. }
  1424. }
  1425. List<Task<List<SchoolInfo>>> tasks = new List<Task<List<SchoolInfo>>>();
  1426. //datas.ForEach(x =>
  1427. //{
  1428. // tasks.Add(GetSchoolAsync(x));
  1429. //});
  1430. List<SchoolInfo> schoolInfos = new List<SchoolInfo>();
  1431. //var schools = await Task.WhenAll(tasks);
  1432. //var schools =await GetSchoolAsync(cityids);
  1433. // schoolInfos.AddRange(schools);
  1434. //foreach (var schs in schools)
  1435. //{
  1436. // schoolInfos.AddRange(schs);
  1437. //}
  1438. List<string> nodatas = new List<string>();
  1439. foreach (var data in datas) {
  1440. (List<SchoolInfo> schoolIn, List<string> nodata) = await GetSchoolAsync(data);
  1441. schoolInfos.AddRange(schoolIn);
  1442. nodatas.AddRange(nodata);
  1443. }
  1444. await _dingDing.SendBotMsg($"os,test,{nodatas.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
  1445. return Ok(schoolInfos);
  1446. */
  1447. return Ok();
  1448. }
  1449. public async Task<(List<SchoolInfo> schoolInfos, List<string> nodata)> GetSchoolAsync(List<string> regions)
  1450. {
  1451. List<SchoolInfo> schools = new List<SchoolInfo>();
  1452. List<string> nodata = new List<string>();
  1453. foreach (var region in regions)
  1454. {
  1455. Dictionary<string, object> data = new Dictionary<string, object>();
  1456. data.Add("method", "api/School/getSchool");
  1457. data.Add("params", new { CountryId = "CN", CityId = region });
  1458. HttpResponseMessage responseMessage = await _httpClient.CreateClient().PostAsJsonAsync("https://contest.teammodel.cn/api/School/getSchool", data);
  1459. if (responseMessage.StatusCode == HttpStatusCode.OK)
  1460. {
  1461. string Content = await responseMessage.Content.ReadAsStringAsync();
  1462. try
  1463. {
  1464. Content.ToObject<JsonElement>().TryGetProperty("result", out JsonElement content);
  1465. if (content.ValueKind.Equals(JsonValueKind.Object) && content.TryGetProperty("data", out JsonElement _data))
  1466. {
  1467. if (_data.ValueKind.Equals(JsonValueKind.Array))
  1468. {
  1469. List<SchoolInfo> infos = _data.ToObject<List<SchoolInfo>>();
  1470. if (infos.IsNotEmpty())
  1471. {
  1472. schools.AddRange(infos.Where(x => x.name != null && x.cityName != null).ToList());
  1473. }
  1474. }
  1475. else
  1476. {
  1477. nodata.Add(data.ToJsonString());
  1478. continue;
  1479. }
  1480. }
  1481. else
  1482. {
  1483. nodata.Add(data.ToJsonString());
  1484. continue;
  1485. }
  1486. }
  1487. catch (Exception ex)
  1488. {
  1489. nodata.Add(data.ToJsonString());
  1490. throw new Exception(ex.Message, ex.InnerException);
  1491. }
  1492. }
  1493. }
  1494. return (schools, nodata);
  1495. }
  1496. public class SchoolInfo
  1497. {
  1498. public string typeName { get; set; }
  1499. public string provinceName { get; set; }
  1500. public string provinceId { get; set; }
  1501. public string id { get; set; }
  1502. public string name { get; set; }
  1503. public string cityId { get; set; }
  1504. public string cityName { get; set; }
  1505. public string address { get; set; }
  1506. }
  1507. public class CodeName
  1508. {
  1509. public string code { get; set; }
  1510. public string name { get; set; }
  1511. }
  1512. /// <summary>
  1513. /// 测试blob多线程写入同一个文件
  1514. /// </summary>
  1515. /// <returns></returns>
  1516. [ProducesDefaultResponseType]
  1517. [HttpPost("generate-school-codes")]
  1518. public async Task<IActionResult> GenerateSchoolCodes(JsonElement json)
  1519. {
  1520. List<SchoolData> schoolss = json.GetProperty("schools").ToObject<List<SchoolData>>();
  1521. dynamic data = await SchoolService.GenerateSchoolCode(schoolss, _dingDing, _environment);
  1522. return Ok(data);
  1523. }
  1524. private async Task<int> SendNotification()
  1525. {
  1526. // _httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {token.AccessToken}");
  1527. var pa = new { grant_type = "device", client_id = "9794e418-c4ef-4fd5-a42d-accaa2d96d6e", client_secret = "ruL?I79h0w1AZaZXtBaZeZuQLQXLa=:-" };
  1528. HttpResponseMessage responseMessage = await _httpClient.CreateClient().PostAsJsonAsync("https://api2-rc.teammodel.net/oauth2/token", pa);
  1529. if (responseMessage.StatusCode == HttpStatusCode.OK)
  1530. {
  1531. return 200;
  1532. }
  1533. else if (responseMessage.StatusCode == HttpStatusCode.Unauthorized)
  1534. {
  1535. return 401;
  1536. }
  1537. else
  1538. {
  1539. return 500;
  1540. }
  1541. }
  1542. /// <summary>
  1543. /// 测试redis通配符
  1544. /// </summary>
  1545. /// <param name="request"></param>
  1546. /// <returns></returns>
  1547. [ProducesDefaultResponseType]
  1548. [HttpGet("test-delete-read")]
  1549. public async Task<IActionResult> TestDelete()
  1550. {
  1551. foreach (var cnt in _azureStorage.GetBlobServiceClient().GetBlobContainers())
  1552. {
  1553. Console.WriteLine(cnt.Name);
  1554. }
  1555. await SendNotification();
  1556. var client = _azureCosmos.GetCosmosClient();
  1557. string aaa = "0";
  1558. try
  1559. {
  1560. ItemResponse<Student> a = await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemAsync<Student>("1111111", new PartitionKey($"Course-111111"));
  1561. Ok(a.StatusCode);
  1562. }
  1563. catch (CosmosException ex)
  1564. {
  1565. if (ex.StatusCode ==HttpStatusCode.NotFound)
  1566. {
  1567. aaa = "404";
  1568. }
  1569. }
  1570. try
  1571. {
  1572. ItemResponse<Student> a = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<Student>("1111111", new PartitionKey($"Course-111111"));
  1573. Ok(a.StatusCode);
  1574. }
  1575. catch (CosmosException ex)
  1576. {
  1577. if (ex.StatusCode == HttpStatusCode.NotFound)
  1578. {
  1579. aaa = aaa + " 404";
  1580. }
  1581. }
  1582. try
  1583. {
  1584. var a = await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemStreamAsync("1111111", new PartitionKey($"Course-111111"));
  1585. Ok(a.StatusCode);
  1586. }
  1587. catch (CosmosException ex)
  1588. {
  1589. if (ex.StatusCode == HttpStatusCode.NotFound)
  1590. {
  1591. aaa = "404";
  1592. }
  1593. }
  1594. try
  1595. {
  1596. var a = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemStreamAsync("1111111", new PartitionKey($"Course-111111"));
  1597. Ok(a.StatusCode);
  1598. }
  1599. catch (CosmosException ex)
  1600. {
  1601. if (ex.StatusCode == HttpStatusCode.NotFound)
  1602. {
  1603. aaa = aaa + " 404";
  1604. }
  1605. }
  1606. return Ok(new { aaa });
  1607. }
  1608. /// <summary>
  1609. /// 测试redis通配符
  1610. /// </summary>
  1611. /// <param name="request"></param>
  1612. /// <returns></returns>
  1613. [ProducesDefaultResponseType]
  1614. [HttpGet("test-redis")]
  1615. public async Task<IActionResult> TestRedis()
  1616. {
  1617. try
  1618. {
  1619. var client = _azureCosmos.GetCosmosClient();
  1620. List<ItemInfo> items = new List<ItemInfo>();
  1621. var queryslt = $"SELECT value(c) FROM c where c.pid = null ";
  1622. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIteratorSql<ItemInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-hbcn") }))
  1623. {
  1624. items.Add(item);
  1625. }
  1626. List<ItemCond> itemConds = new List<ItemCond>();
  1627. items.GroupBy(x => x.periodId).Select(y => new { key = y.Key, list = y.ToList() }).ToList().ForEach(z =>
  1628. {
  1629. ItemCond cond = new ItemCond() { id = z.key, code = $"ItemCond-hbcn", pk = "ItemCond", ttl = -1, count = z.list.Count, grades = new List<GradeCount>(), subjects = new List<SubjectItemCount>() };
  1630. z.list.ForEach(y =>
  1631. {
  1632. ItemService.CountItemCond(y, null, cond);
  1633. });
  1634. itemConds.Add(cond);
  1635. });
  1636. itemConds.ForEach(async cond =>
  1637. {
  1638. await client.GetContainer(Constant.TEAMModelOS, "School").UpsertItemAsync<ItemCond>(cond, new PartitionKey(cond.code));
  1639. });
  1640. return Ok(new { itemConds });
  1641. }
  1642. catch (Exception ex) { await _dingDing.SendBotMsg($"TEAMModelFunction,ActivityHttpTrigger,fix-itemcond()\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組); }
  1643. return Ok(new { });
  1644. }
  1645. /// <summary>
  1646. ///
  1647. /// </summary>
  1648. /// <param name="request"></param>
  1649. /// <returns></returns>
  1650. [ProducesDefaultResponseType]
  1651. //[AuthToken(Roles = "teacher")]
  1652. [HttpPost("get-DownloadContent-item")]
  1653. public async Task<IActionResult> DownloadContentItem(JsonElement request)
  1654. {
  1655. ItemBlob itemBlob = null;
  1656. try
  1657. {
  1658. BlobDownloadInfo blobDownloadResult = await _azureStorage.GetBlobContainerClient($"hbcn").GetBlobClient($"/item/12b865c9-a223-278a-2be1-e336b9ead99e/12b865c9-a223-278a-2be1-e336b9ead99e.json")
  1659. .DownloadAsync();
  1660. if (blobDownloadResult != null)
  1661. {
  1662. var json = JsonDocument.Parse(blobDownloadResult.Content);
  1663. itemBlob = json.RootElement.ToObject<ItemBlob>();
  1664. }
  1665. }
  1666. catch (Exception ex)
  1667. {
  1668. itemBlob = null;
  1669. }
  1670. return Ok(new { itemBlob });
  1671. }
  1672. /// <summary>
  1673. ///
  1674. /// </summary>
  1675. /// <param name="request"></param>
  1676. /// <returns></returns>
  1677. [ProducesDefaultResponseType]
  1678. //[AuthToken(Roles = "teacher")]
  1679. [HttpPost("get-bind-data")]
  1680. public async Task<IActionResult> GetData(JsonElement request)
  1681. {
  1682. var areaId = request.GetProperty("areaId");
  1683. var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
  1684. List<ScTeacher> teachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object> { { "PartitionKey", "ScTeacher" }, { "areaId", $"{areaId}" } });
  1685. return Ok(teachers.Select(x => new { x.areaId, x.PXID, x.TID, x.TeacherName, x.tmdid, x.SchoolName, x.DisName }));
  1686. }
  1687. /// 删除
  1688. /// </summary>
  1689. /// <param name="request"></param>
  1690. /// <returns></returns>
  1691. [ProducesDefaultResponseType]
  1692. [AuthToken(Roles = "admin,teacher")]
  1693. [HttpPost("get-save-log")]
  1694. public async Task<IActionResult> SaveLog(JsonElement request)
  1695. {
  1696. BlobDownloadResult Recording = await _azureStorage.GetBlobContainerClient("1595321354").GetBlobClient($"records/271528531841781760/Record/.Recording.json").DownloadContentAsync();
  1697. var json = Recording.Content.ToString();
  1698. var jsonByte = Encoding.UTF8.GetBytes(json);
  1699. Stream stream = new MemoryStream(jsonByte);
  1700. var doc = JsonDocument.Parse(stream);
  1701. School school = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>("hbcn", new PartitionKey("Base"));
  1702. _ = _azureStorage.SaveLog("find-school", school.ToJsonString(), httpContext: HttpContext, dingDing: _dingDing, scope: "school");
  1703. return Ok(new { doc, school, });
  1704. }
  1705. /// <summary>
  1706. ///
  1707. /// </summary>
  1708. /// <param name="request"></param>
  1709. /// <returns></returns>
  1710. [ProducesDefaultResponseType]
  1711. //[AuthToken(Roles = "teacher")]
  1712. [HttpPost("get-ip")]
  1713. public async Task<IActionResult> GetIp(JsonElement request)
  1714. {
  1715. try
  1716. {
  1717. BlobDownloadResult baseblobDownload = await _azureStorage.GetBlobContainerClient("habook").GetBlobClient($"/records/299813002894381056/IES/Base.json").DownloadContentAsync();
  1718. LessonBase lessonBase = baseblobDownload.Content.ToObjectFromJson<LessonBase>();
  1719. return Ok(lessonBase);
  1720. }
  1721. catch (RequestFailedException ex) when (ex.Status == 404)
  1722. {
  1723. return BadRequest("文件不存在!");
  1724. }
  1725. LessonBase lessonBases = request.ToObject<LessonBase>();
  1726. //List<TmdInfo> tmds= request.ToObject<List<TmdInfo>>();
  1727. //var content = new StringContent(tmds.Select(x=>x.id).ToJsonString(), Encoding.UTF8, "application/json");
  1728. //string json = await _coreAPIHttpService.GetUserInfos(content);
  1729. //string _researchKey = Regex.Replace($"{request.GetProperty("key")}", "[ \\[ \\] \\^ \\-|()【】/' {}_*×――(^)$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", " ");
  1730. //string[] mm = Regex.Split(_researchKey, "\\s+", RegexOptions.IgnoreCase);
  1731. //var token = await CoreTokenExtensions.CreateAccessToken("c7317f88-7cea-4e48-ac57-a16071f7b884", "kguxh:V.PLmxBdaI@jnrTrDSth]A3346", "China");
  1732. //string ip = await _searcher.SearchIpAsync($"{request.GetProperty("ip")}");
  1733. // return Ok(new { activity, ip, token.AccessToken,token.TokenType,token.IdToken, mm });
  1734. return Ok(lessonBases);
  1735. }
  1736. /// 删除
  1737. /// </summary>
  1738. /// <param name="request"></param>
  1739. /// <returns></returns>
  1740. [ProducesDefaultResponseType]
  1741. [HttpPost("check-online-record")]
  1742. public async Task<IActionResult> CheckOnlinerecord(JsonElement request)
  1743. {
  1744. string sql = $"select c.id,c.name ,b.schoolId as code from c join b in c.schools where b.areaId='9ae614ba-0771-4502-a56e-0537bc5207c3'";
  1745. List<IdNameCode> codes = new List<IdNameCode>();
  1746. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryIteratorSql<IdNameCode>(sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
  1747. {
  1748. codes.Add(item);
  1749. }
  1750. List<dynamic> data = new List<dynamic>(); ;
  1751. foreach (IdNameCode code in codes)
  1752. {
  1753. try
  1754. {
  1755. TeacherTrain train = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<TeacherTrain>(code.id, new PartitionKey($"TeacherTrain-{code.code}"));
  1756. data.Add(new { code.id, code.name, code.code, train.totalTime, train.onlineTime, train.classTime, train.offlineTime });
  1757. }
  1758. catch (Exception ex)
  1759. {
  1760. data.Add(new { code.id, code.name, code.code, totalTime = 0, onlineTime = 0, classTime = 0, offlineTime = 0 });
  1761. }
  1762. }
  1763. return Ok(new { data });
  1764. }
  1765. [HttpPost("test-scteacher")]
  1766. public async Task<IActionResult> TestScteacher(JsonElement json)
  1767. {
  1768. var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
  1769. List<ScTeacher> teachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", "ScTeacher" }, { "areaId", "e6fb5d40-bd85-7327-cea8-ea5c642836d2" }, { "SchoolName", "岳池县大佛初级中学校" } });
  1770. //var techs= teachers.Where(t => string.IsNullOrWhiteSpace(t.tmdid));
  1771. return Ok(teachers);
  1772. }
  1773. [HttpPost("get-token")]
  1774. public async Task<IActionResult> GetToken(JsonElement request)
  1775. {
  1776. if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
  1777. if (!request.TryGetProperty("host", out JsonElement host)) return BadRequest();
  1778. if (!request.TryGetProperty("name", out JsonElement name)) return BadRequest();
  1779. if (!request.TryGetProperty("picture", out JsonElement picture)) return BadRequest();
  1780. if (!request.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
  1781. if (!request.TryGetProperty("school", out JsonElement school)) return BadRequest();
  1782. int timezone = 8;
  1783. if (HttpContext.Request.Headers.TryGetValue("Time-Zone", out var Time_Zone) && int.TryParse(Time_Zone, out int tz))
  1784. {
  1785. timezone=tz;
  1786. }
  1787. var auth_token = JwtAuthExtension.CreateAuthToken(host.ToString(), id.ToString(), name.ToString(),
  1788. picture.ToString(), _option.JwtSecretKey,
  1789. scope: "student", Website: "IES",timezone, areaId: areaId.ToString(),schoolID: school.ToString(), roles: new[] { "student" }, expire: 1);
  1790. //var techs= teachers.Where(t => string.IsNullOrWhiteSpace(t.tmdid));
  1791. return Ok(auth_token);
  1792. }
  1793. [HttpPost("test-scteacher-dn")]
  1794. public async Task<IActionResult> TestScteacherDn(JsonElement json)
  1795. {
  1796. var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
  1797. string sqls = "select distinct value(c.id )from c where c.code='Base' and IS_DEFINED(c.finalScore)=true ";
  1798. //https://teammodelos.blob.core.chinacloudapi.cn/teammodelos
  1799. //https://teammodelos.blob.core.chinacloudapi.cn/teammodelos/yxpt%2Fjinniu%2Fscbind%2F1647432004.json
  1800. List<ScTeacher> teachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", "ScTeacher" }, { "areaId", "870a5a6b-1ab3-461a-bdeb-baec19780ddb" } });
  1801. List<string> ids = new List<string>();
  1802. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
  1803. .GetItemQueryIteratorSql<string>(sqls, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
  1804. {
  1805. ids.Add(item);
  1806. }
  1807. long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  1808. List<string> erorr = new List<string>();
  1809. List<ScTeacher> teachersUp = new List<ScTeacher>();
  1810. foreach (var id in ids)
  1811. {
  1812. try
  1813. {
  1814. BlobDownloadResult baseblobDownload = await _azureStorage.GetBlobContainerClient("teammodelos").GetBlobClient($"/yxpt/jinniu/scbind/{id}.json").DownloadContentAsync();
  1815. ScBindData scBindData = baseblobDownload.Content.ToObjectFromJson<ScBindData>();
  1816. var tcd = teachers.Find(x => x.RowKey.Equals(scBindData.pxid));
  1817. if (tcd != null)
  1818. {
  1819. Teacher teacher = new Teacher
  1820. {
  1821. createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
  1822. pk = "Base",
  1823. code = "Base",
  1824. id = id,
  1825. name = scBindData.username,
  1826. size = 2,
  1827. defaultSchool = tcd.schoolCode,
  1828. schools = new List<TeacherSchool> {
  1829. new TeacherSchool
  1830. {
  1831. schoolId = tcd.schoolCode, status = "join", time = now, name = scBindData.sn, areaId = tcd.areaId
  1832. }
  1833. },
  1834. binds = new List<ThirdBind> {
  1835. new ThirdBind
  1836. {
  1837. type= "scsyxpt",userid=scBindData.userid,username= scBindData.username,account=scBindData.account,data=new List<string>{ scBindData.ToJsonString()}
  1838. }
  1839. }
  1840. };
  1841. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(teacher, new PartitionKey("Base"));
  1842. tcd.tmdid = id;
  1843. teachersUp.Add(tcd);
  1844. }
  1845. }
  1846. catch (Exception)
  1847. {
  1848. erorr.Add(id);
  1849. }
  1850. }
  1851. await table.SaveOrUpdateAll(teachersUp);
  1852. return Ok();
  1853. }
  1854. [HttpPost("fix-jinniupujiang-teacher-videotime")]
  1855. public async Task<IActionResult> GetScteacher(JsonElement json)
  1856. {
  1857. if (!json.TryGetProperty("areaId", out JsonElement _areaId)) { return BadRequest(); }
  1858. Area area = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).ReadItemAsync<Area>($"{_areaId}", new PartitionKey("Base-Area"));
  1859. AreaSetting setting = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).ReadItemAsync<AreaSetting>($"{_areaId}", new PartitionKey("AreaSetting"));
  1860. List<string> teachers = new List<string>();
  1861. //获取这个区的教师 //psywgy
  1862. string schoolSql = $"SELECT value c.id FROM c join a in c.schools where a.areaId='{_areaId}' and c.code='Base' ";
  1863. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
  1864. .GetItemQueryIteratorSql<string>(schoolSql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
  1865. {
  1866. teachers.Add(item);
  1867. }
  1868. //获取这些老师的研修记录
  1869. string tr = $"SELECT distinct value(c) FROM c join a in c.currency.teacherAilities where c.id in ({string.Join(",", teachers.Select(x => $"'{x}'"))}) and c.pk='TeacherTrain' and a.videoTime<300 ";
  1870. List<TeacherTrain> teacherTrains = new List<TeacherTrain>();
  1871. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
  1872. .GetItemQueryIteratorSql<TeacherTrain>(tr, requestOptions: new QueryRequestOptions { }))
  1873. {
  1874. if (!item.tmdid.Equals("1528783259") || !item.tmdid.Equals("1530606136"))
  1875. {
  1876. teacherTrains.Add(item);
  1877. }
  1878. }
  1879. //获取这个区的能力点树状结构
  1880. string sql = $" select distinct value(b.id ) from c join b in c.children where c.code='AbilityTask-{area.standard}' ";
  1881. List<string> nodeIdsDB = new List<string>();
  1882. await foreach (var y in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).GetItemQueryIteratorSql<string>
  1883. (sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilityTask-{area.standard}") }))
  1884. {
  1885. nodeIdsDB.Add(y);
  1886. }
  1887. List<AbilitySub> abilitySubs = new List<AbilitySub>();
  1888. List<TeacherVideoTime> teacherVideoTimes = new List<TeacherVideoTime>();
  1889. string ids = teacherTrains.Select(x => x.id).ToJsonString();
  1890. string sqls = $" select value(c) from c where c.code='AbilityTask-{area.standard}'";
  1891. List<AbilityTask> abilityTasks = new List<AbilityTask>();
  1892. Dictionary<string, RecordFileAbility> valuePairs = new Dictionary<string, RecordFileAbility>();
  1893. await foreach (var y in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).GetItemQueryIteratorSql<AbilityTask>
  1894. (sqls, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilityTask-{area.standard}") }))
  1895. {
  1896. abilityTasks.Add(y);
  1897. }
  1898. foreach (var item in teacherTrains)
  1899. {
  1900. List<TeacherAbility> teacherAbility = new List<TeacherAbility>();
  1901. if (item.currency.teacherAilities.Count() > 3)
  1902. {
  1903. //如果选择了大于三个能力点的教师,则优先获取上传了认证材料的的能力点,
  1904. var uploadHas = item.currency.teacherAilities.FindAll(x => x.uploadHas == 1 && x.videoTime < 300);
  1905. if (uploadHas.Any())
  1906. {
  1907. teacherAbility.AddRange(uploadHas);
  1908. }
  1909. if (teacherAbility.Count < 3)
  1910. {
  1911. // 如果仍然未满足数量。则再去获取 没有上传认证材料,但是又有学习时间长的能力点。
  1912. var hasVideoTime = item.currency.teacherAilities.FindAll(x => x.uploadHas != 1 && x.videoTime < 300).OrderByDescending(o => o.videoTime);
  1913. var disCount = 3 - teacherAbility.Count;
  1914. teacherAbility.AddRange(hasVideoTime.Take(disCount));
  1915. }
  1916. }
  1917. else
  1918. {
  1919. teacherAbility.AddRange(item.currency.teacherAilities.Where(ab => ab.videoTime < 300));
  1920. }
  1921. TeacherFile teacherFile = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<TeacherFile>(item.id, new PartitionKey($"TeacherFile-{item.code.Replace("TeacherTrain-", "")}"));
  1922. foreach (var ability in teacherAbility)
  1923. {
  1924. TeacherVideoTime teacherVideoTime = new TeacherVideoTime { code = item.code.Replace("TeacherTrain-", ""), id = item.id, abilityId = ability.id, no = ability.no, train_time = ability.videoTime };
  1925. double fileview = 0;
  1926. var filerecord = teacherFile.fileRecords.FindAll(x => x.files.Where(y => y.abilityId.Equals(ability.id)).Count() > 0);
  1927. filerecord.ForEach(x => {
  1928. var file = x.files.FindAll(y => y.abilityId.Equals($"{ability.id}"));
  1929. if (file.IsNotEmpty())
  1930. {
  1931. fileview += x.view;
  1932. }
  1933. });
  1934. double fminut = fileview / 60;
  1935. teacherVideoTime.files_time = fminut;
  1936. var tech = abilityTasks.FindAll(x => x.abilityId.Equals(ability.id));
  1937. // double limit = 0;
  1938. tech.ForEach(task =>
  1939. {
  1940. task.children.ForEach(y =>
  1941. {
  1942. y.rnodes.ForEach(r =>
  1943. {
  1944. if (valuePairs.ContainsKey(r.hash))
  1945. {
  1946. valuePairs.TryGetValue(r.hash, out var value);
  1947. var ablt = value.fileAbilities.Find(z => z.abilityId.Equals(task.abilityId) && z.taskId.Equals(task.id) && z.nodeId.Equals(y.id));
  1948. if (ablt == null)
  1949. {
  1950. value.fileAbilities.Add(new FileAbility { url = r.link, abilityId = task.abilityId, taskId = task.id, nodeId = y.id });
  1951. // limit = limit + r.duration;
  1952. }
  1953. }
  1954. else
  1955. {
  1956. valuePairs.Add(r.hash, new RecordFileAbility
  1957. {
  1958. fileRecord =
  1959. new FileRecord { hash = r.hash, size = r.size.Value, duration = r.duration, view = (int)r.duration, type = r.type, done = true },
  1960. fileAbilities = new List<FileAbility> { new FileAbility { url = r.link, abilityId = task.abilityId, taskId = task.id, nodeId = y.id } }
  1961. });
  1962. // limit = limit + r.duration;
  1963. }
  1964. });
  1965. });
  1966. });
  1967. HashSet<string> childIds = new HashSet<string>();
  1968. foreach (var ps in valuePairs)
  1969. {
  1970. HashSet<string> abilityIds = teacherFile.fileRecords.SelectMany(x => x.files).Select(x => x.abilityId).Where(abid => abid.Equals(ability.id)).ToHashSet();
  1971. double view = 0;
  1972. foreach (var abid in abilityIds)
  1973. {
  1974. var record = teacherFile.fileRecords.FindAll(x => x.files.Where(y => y.abilityId.Equals(abid)).Count() > 0);
  1975. record.ForEach(x => {
  1976. var file = x.files.FindAll(y => y.abilityId.Equals($"{abid}"));
  1977. if (file.IsNotEmpty())
  1978. {
  1979. view += x.view;
  1980. }
  1981. });
  1982. }
  1983. double minut = view / 60;
  1984. teacherVideoTime.after_time = minut;
  1985. if (minut < 300)
  1986. {
  1987. var fils = teacherFile.fileRecords.Find(x => x.hash.Equals(ps.Key));
  1988. if (fils != null)
  1989. {
  1990. ps.Value.fileAbilities.ForEach(x =>
  1991. {
  1992. var a = fils.files.Find(z => z.nodeId.Equals(x.nodeId) && z.abilityId.Equals(x.abilityId));
  1993. if (a == null)
  1994. {
  1995. childIds.Add(x.nodeId);
  1996. fils.files.Add(new FileAbility { url = x.url, abilityId = x.abilityId, taskId = x.taskId, nodeId = x.nodeId });
  1997. }
  1998. });
  1999. }
  2000. else
  2001. {
  2002. ps.Value.fileAbilities.ForEach(x =>
  2003. {
  2004. childIds.Add(x.nodeId);
  2005. });
  2006. teacherFile.fileRecords.Add(new FileRecord
  2007. {
  2008. hash = ps.Value.fileRecord.hash,
  2009. size = ps.Value.fileRecord.size,
  2010. duration = ps.Value.fileRecord.duration,
  2011. view = (int)ps.Value.fileRecord.view,
  2012. type = ps.Value.fileRecord.type,
  2013. done = true,
  2014. files = ps.Value.fileAbilities
  2015. });
  2016. }
  2017. }
  2018. else
  2019. {
  2020. break;
  2021. }
  2022. }
  2023. if (childIds.Any())
  2024. {
  2025. string code = teacherFile.code.Replace("TeacherFile-", "");
  2026. if (!string.IsNullOrWhiteSpace(code))
  2027. {
  2028. try
  2029. {
  2030. AbilitySub abilitySub = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<AbilitySub>(ability.id, new PartitionKey($"AbilitySub-{code}-{teacherFile.id}"));
  2031. var taskIds = abilitySub.taskRcds.Select(x => x.id);
  2032. var notin = childIds.Except(taskIds);
  2033. if (notin.Any())
  2034. {
  2035. abilitySub.taskRcds.AddRange(notin.Select(x => new AbilityTaskRcd { id = x, done = true }));
  2036. abilitySubs.Add(abilitySub);
  2037. }
  2038. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync(abilitySub, abilitySub.id, new PartitionKey($"AbilitySub-{code}-{teacherFile.id}"));
  2039. }
  2040. catch (Exception ex)
  2041. {
  2042. }
  2043. }
  2044. }
  2045. teacherVideoTimes.Add(teacherVideoTime);
  2046. }
  2047. teacherFile = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync<TeacherFile>(teacherFile, teacherFile.id, new PartitionKey(teacherFile.code));
  2048. item.update.Add(StatisticsService.TeacherAbility);
  2049. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync<TeacherTrain>(item, item.id, new PartitionKey(item.code));
  2050. }
  2051. var data = teacherVideoTimes.GroupBy(x => x.code).Select(x => new { x.Key, count = x.ToList().Count, list = x.ToList() }).OrderByDescending(x => x.count);
  2052. return Ok(new { data, abilitySubs });
  2053. }
  2054. public class TeacherVideoTime
  2055. {
  2056. public string code { get; set; }
  2057. public string id { get; set; }
  2058. public string abilityId { get; set; }
  2059. public string no { get; set; }
  2060. public double train_time { get; set; }
  2061. public double files_time { get; set; }
  2062. public double after_time { get; set; }
  2063. }
  2064. [HttpPost("get-teacher-video")]
  2065. public async Task<IActionResult> GetScteacherClassVideo(JsonElement json)
  2066. {
  2067. string sql = " SELECT c.id ,c.school as code FROM c where c.pk='ClassVideo' and c.school<>'SYSTEM_NO_SCHOOL' and ARRAY_LENGTH(c.files)>0 ";
  2068. List<IdNameCode> idNameCodes = new List<IdNameCode>();
  2069. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryIteratorSql<IdNameCode>(sql, requestOptions: new QueryRequestOptions { }))
  2070. {
  2071. idNameCodes.Add(item);
  2072. }
  2073. foreach (var item in idNameCodes)
  2074. {
  2075. try
  2076. {
  2077. TeacherTrain teacherTrain = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<TeacherTrain>(item.id, new PartitionKey($"TeacherTrain-{item.code}"));
  2078. if (!teacherTrain.teacherClasses.Any())
  2079. {
  2080. teacherTrain.update.Add("TeacherClass");
  2081. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync<TeacherTrain>(teacherTrain, teacherTrain.id, new PartitionKey($"TeacherTrain-{item.code}"));
  2082. }
  2083. }
  2084. catch (Exception ex)
  2085. {
  2086. continue;
  2087. }
  2088. }
  2089. return Ok();
  2090. }
  2091. [HttpPost("test-batch")]
  2092. public async Task<IActionResult> TestBatchFUN(JsonElement json)
  2093. {
  2094. List<Task<ItemResponse<TestBatch>>> nameCodes = new List<Task<ItemResponse<TestBatch>>>();
  2095. for (int i = 0; i < 10; i++)
  2096. {
  2097. nameCodes.Add(_azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).
  2098. CreateItemAsync(new TestController.TestBatch { id = Guid.NewGuid().ToString(), code = $"TestBatch-{i}", pk = "TestBatch" }, new PartitionKey($"TestBatch-{i}")));
  2099. }
  2100. await Task.WhenAll(nameCodes);
  2101. return Ok();
  2102. }
  2103. public class TestBatch : CosmosEntity
  2104. {
  2105. }
  2106. [HttpPost("export-teacher")]
  2107. public async Task<IActionResult> ExportTeacher(JsonElement json)
  2108. {
  2109. List<string> schools = new()
  2110. {
  2111. "dghznx",
  2112. "cxhhlx",
  2113. "xjaxx",
  2114. "zjqxx",
  2115. "xnygxx",
  2116. "lxxcfx",
  2117. "gxjrxx",
  2118. "cdgxsx",
  2119. "yzxx",
  2120. "kjyxx",
  2121. "wjylxx",
  2122. "dsgjxx",
  2123. "ydzt",
  2124. "xndbxx",
  2125. "sqtszx",
  2126. "cdxczx",
  2127. "ghsyzx",
  2128. "lqsx",
  2129. "cdxxps",
  2130. "xcfx",
  2131. "xyqxx",
  2132. "xncbyy",
  2133. "cdlqjk",
  2134. "lqdmxx",
  2135. "lqyx",
  2136. "pclxxx",
  2137. "cdfzx",
  2138. "xnblxx",
  2139. "ghsx",
  2140. "khdycz",
  2141. "khbmxx",
  2142. "khdecz",
  2143. "khzx",
  2144. "khhbzx",
  2145. "gxxcxx",
  2146. "khhtxx",
  2147. "khdxxx",
  2148. "khsyxx"
  2149. };
  2150. var cosmosClient = _azureCosmos.GetCosmosClient();
  2151. foreach (var item in schools)
  2152. {
  2153. School school = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemAsync<School>($"{item}", new PartitionKey("Base"));
  2154. List<Teacher> teachers = new();
  2155. await foreach (var tch in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIteratorSql<Teacher>(queryText:
  2156. $"SELECT value(c) FROM c join s in c.schools where s.schoolId='{item}' and c.code='Base'",
  2157. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  2158. {
  2159. teachers.Add(tch);
  2160. }
  2161. if (teachers.Count > 0)
  2162. {
  2163. foreach (var teacher in teachers)
  2164. {
  2165. teacher.schools.ForEach(tch => { if (tch.schoolId.Equals(item)) { tch.areaId = school.areaId; } });
  2166. await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
  2167. }
  2168. }
  2169. }
  2170. return Ok();
  2171. }
  2172. public class RecordFileAbility
  2173. {
  2174. public FileRecord fileRecord { get; set; }
  2175. public List<FileAbility> fileAbilities { get; set; }
  2176. }
  2177. [HttpPost("test-blob-folder")]
  2178. public async Task<IActionResult> TestBlobFolder(JsonElement json)
  2179. {
  2180. string location = _option.Location;
  2181. bool lockKey = await _azureRedis.GetRedisClient(8).KeyExistsAsync($"LessonRecord:Unused:Lock:{location}");
  2182. //key不存在的时候 。
  2183. if (!lockKey)
  2184. {
  2185. var schoolKeys = new List<IdCodeCount>();
  2186. var teacherKeys = new List<IdCodeCount>();
  2187. string sql = "select value c.id from c where c.code='Base'";
  2188. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).
  2189. GetItemQueryIteratorSql<string>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
  2190. {
  2191. teacherKeys.Add(new IdCodeCount { id = item, code = "Teacher" });
  2192. }
  2193. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).
  2194. GetItemQueryIteratorSql<string>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
  2195. {
  2196. schoolKeys.Add(new IdCodeCount { id = item, code = "School" });
  2197. }
  2198. string sqlcount = "select value count(1) from c where c.pk='LessonRecord'";
  2199. foreach (var key in schoolKeys)
  2200. {
  2201. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).
  2202. GetItemQueryIteratorSql<int>(queryText: sqlcount, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"LessonRecord-{key.id}") }))
  2203. {
  2204. key.count = item;
  2205. break;
  2206. }
  2207. }
  2208. foreach (var key in teacherKeys)
  2209. {
  2210. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).
  2211. GetItemQueryIteratorSql<int>(queryText: $"select value count(1) from c where c.pk='LessonRecord' and c.tmdid='{key.id}'",
  2212. requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"LessonRecord") }))
  2213. {
  2214. key.count = item;
  2215. break;
  2216. }
  2217. }
  2218. schoolKeys.AddRange(teacherKeys);
  2219. //以下代码作用,用于根据当前拥有的课例数判断区分学校和个人使用课例频率越多的,
  2220. //并均分每次需要处理的学校和个人容器个数,避免每次处理批次花费时间相差太大。
  2221. //将每个批次处理数量级控制在500-1000左右。
  2222. List<IEnumerable<IdCodeCount>> counts = new List<IEnumerable<IdCodeCount>>();
  2223. //501-∞
  2224. var count501_ = schoolKeys.Where(x => x.count >= 501); //至少500条
  2225. counts.AddRange(count501_.Page(1));//1个学校
  2226. //201-500
  2227. var count201_500 = schoolKeys.Where(x => x.count >= 201 && x.count <= 500); //至少402条-1000条
  2228. counts.AddRange(count201_500.Page(2));//2个学校
  2229. //100-200
  2230. var count100_200 = schoolKeys.Where(x => x.count >= 100 && x.count <= 200);//至少500条-1000条
  2231. counts.AddRange(count100_200.Page(5));//5个学校
  2232. //51-99
  2233. var count51_99 = schoolKeys.Where(x => x.count >= 51 && x.count <= 99);//至少500条-990条
  2234. counts.AddRange(count51_99.Page(10));//10个学校
  2235. //21-50
  2236. var count21_50 = schoolKeys.Where(x => x.count >= 21 && x.count <= 50);//至少410条-1000条
  2237. counts.AddRange(count21_50.Page(20));//20个学校
  2238. //10-20
  2239. var count10_20 = schoolKeys.Where(x => x.count >= 10 && x.count <= 20);//至少500条-1000条
  2240. counts.AddRange(count10_20.Page(50));//50个学校
  2241. //5-9
  2242. var count0_9 = schoolKeys.Where(x => x.count >= 5 && x.count <= 9);//至少500条-900条
  2243. counts.AddRange(count0_9.Page(100));//100个学校
  2244. //2-4
  2245. var count2_4 = schoolKeys.Where(x => x.count >= 2 && x.count <= 4);//至少500条-1000条
  2246. counts.AddRange(count2_4.Page(250));
  2247. //0-1
  2248. var count0_1 = schoolKeys.Where(x => x.count >= 0 && x.count <= 1);//至少500,就算没有课例也算一次。
  2249. counts.AddRange(count0_1.Page(500));
  2250. int field = 1;
  2251. counts.Count();
  2252. foreach (var item in counts)
  2253. {
  2254. bool stuallstatus = await _azureRedis.GetRedisClient(8).HashSetAsync($"LessonRecord:Unused:Lock:{location}", field, new { status = 0, item }.ToJsonString());
  2255. field += 1;
  2256. }
  2257. await _dingDing.SendBotMsg($"{location},获取到:{schoolKeys.Count} 个学校和个人的容器\n" +
  2258. $"大概要处理:{schoolKeys.Sum(x => x.count) + schoolKeys.Where(x => x.count >= 0).Count()} 条数据\n" +
  2259. $"将数据分为:{field - 1} 次处理,每次处理500-1000条数据。", GroupNames.醍摩豆服務運維群組);
  2260. }
  2261. return Ok(new { });
  2262. }
  2263. public class IdCodeCount
  2264. {
  2265. public string id { get; set; }
  2266. public string code { get; set; }
  2267. public int count { get; set; }
  2268. }
  2269. /// <summary>
  2270. /// 随机获取三个不同类型的题目
  2271. /// </summary>
  2272. /// <param name="request"></param>
  2273. /// <returns></returns>
  2274. [HttpPost("gen-pdf")]
  2275. //[Authorize(Roles = Constant.Role_Root)]
  2276. public IActionResult GenPdf(JsonElement json)
  2277. {
  2278. //https://article.itxueyuan.com/JAxOnG
  2279. //http://t.zoukankan.com/hsiang-p-14608694.html
  2280. //https://github.com/rdvojmoc/DinkToPdf
  2281. //https://blog.csdn.net/u011966339/article/details/114964016?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-0-114964016-blog-118609642.pc_relevant_antiscanv2&spm=1001.2101.3001.4242.1&utm_relevant_index=3
  2282. var html = @"
  2283. <!DOCTYPE html>
  2284. <html>
  2285. <head>
  2286. <meta charset=""UTF-8"">
  2287. <meta http-equiv=""X-UA-Compatible"" content=""IE=edge"">
  2288. <meta name=""viewport"" content=""width=device-width, initial-scale=1.0"">
  2289. <title>校本研修活动完成情况</title>
  2290. <style>
  2291. body {
  2292. font-family: ""fangsong"";
  2293. display: flex;
  2294. flex-direction: column;
  2295. align-items: center;
  2296. }
  2297. .tch-table,
  2298. .details-table {
  2299. width: 100%;
  2300. }
  2301. .tch-table table {
  2302. width: 100%;
  2303. margin: 15px 0;
  2304. border: 0;
  2305. }
  2306. .tch-table th {
  2307. background-color: #c5c5c5;
  2308. color: #222222;
  2309. }
  2310. .tch-table,
  2311. .tch-table th,
  2312. .tch-table td {
  2313. font-size: 0.95em;
  2314. text-align: center;
  2315. padding: 4px;
  2316. border-collapse: collapse;
  2317. font-weight: bolder;
  2318. }
  2319. .tch-table th,
  2320. .tch-table td {
  2321. border-bottom: 1px solid #918b8c;
  2322. border-width: 1px 0 1px 0;
  2323. }
  2324. .tch-table tr {
  2325. border: 1px solid #ffffff;
  2326. height: 3.2em;
  2327. }
  2328. .title {
  2329. font-weight: bold;
  2330. align-self: flex-start;
  2331. margin: 30px 5px;
  2332. }
  2333. .title::before {
  2334. content: """";
  2335. width: 10px;
  2336. height: 10px;
  2337. background: #3a3a3a;
  2338. display: inline-block;
  2339. margin-right: 10px;
  2340. }
  2341. </style>
  2342. </head>
  2343. <body>
  2344. <h1 style=""text-align:center;font-weight: bold;"">校本研修活动完成情况</h1>
  2345. <p class=""title"">教师信息</p>
  2346. <table class=""tch-table"" id=""tchTable"">
  2347. <tr>
  2348. <th style=""width: 33.3%;"">教师姓名</th>
  2349. <th style=""width: 33.3%;"">机构</th>
  2350. <th style=""width: 33.3%;"">教研组</th>
  2351. </tr>
  2352. <tr>
  2353. <td>张三</td>
  2354. <td>四川省成都市盐道街中学</td>
  2355. <td>高中政治教研组</td>
  2356. </tr>
  2357. </table>
  2358. <p class=""title"">活动明细</p>
  2359. <table class=""tch-table"" id=""acTable"">
  2360. <tr>
  2361. <th style=""width: 25%;"">活动主题</th>
  2362. <th style=""width: 15%;"">活动类型</th>
  2363. <th style=""width: 5%;"">任务学时</th>
  2364. <th style=""width: 5%;"">完成学时</th>
  2365. <th style=""width: 20%;"">活动时间</th>
  2366. <th style=""width: 10%;"">活动内容</th>
  2367. <th style=""width: 10%;"">活动任务</th>
  2368. <th style=""width: 10%;"">状态</th>
  2369. </tr>
  2370. <tr>
  2371. <td>语文学科如何在A1技术支持下进行学情分析</td>
  2372. <td>信息化教学案例展示与分享</td>
  2373. <td>1</td>
  2374. <td>1</td>
  2375. <td>2022-04-07 到 2022-04-14</td>
  2376. <td></td>
  2377. <td>扫码签到、作业提交、问卷反馈、评测活动</td>
  2378. <td>已完成</td>
  2379. </tr>
  2380. </table>
  2381. </body>
  2382. </html>
  2383. ";
  2384. try
  2385. {
  2386. GlobalSettings globalSettings = new GlobalSettings();
  2387. globalSettings.ColorMode = ColorMode.Color;
  2388. globalSettings.Orientation = Orientation.Portrait;
  2389. globalSettings.PaperSize = PaperKind.A4;
  2390. globalSettings.Margins = new MarginSettings { Top = 25, Bottom = 25 };
  2391. ObjectSettings objectSettings = new ObjectSettings();
  2392. objectSettings.PagesCount = true;
  2393. objectSettings.HtmlContent = html;
  2394. //WebSettings webSettings = new WebSettings();
  2395. //webSettings.DefaultEncoding = "utf-8";
  2396. HeaderSettings headerSettings = new HeaderSettings();
  2397. headerSettings.FontSize = 15;
  2398. headerSettings.FontName = "fangsong";
  2399. headerSettings.Right = "";
  2400. // headerSettings.Line = true;
  2401. FooterSettings footerSettings = new FooterSettings();
  2402. footerSettings.FontSize = 12;
  2403. footerSettings.FontName = "Ariel";
  2404. footerSettings.Center = "校本研修活动完成情况([page]/[toPage])页";
  2405. // footerSettings.Line = true;
  2406. objectSettings.HeaderSettings = headerSettings;
  2407. objectSettings.FooterSettings = footerSettings;
  2408. //objectSettings.WebSettings = webSettings;
  2409. HtmlToPdfDocument htmlToPdfDocument = new HtmlToPdfDocument()
  2410. {
  2411. GlobalSettings = globalSettings,
  2412. Objects = { objectSettings },
  2413. };
  2414. var a = _converter.Convert(htmlToPdfDocument);
  2415. MemoryStream m = new MemoryStream(a);
  2416. FileStream fs = new FileStream("F:\\1111111111111\\SimplePdf1.pdf", FileMode.Create, FileAccess.Write, FileShare.Read);
  2417. m.WriteTo(fs);
  2418. m.Close();
  2419. fs.Close();
  2420. var doc = new HtmlToPdfDocument()
  2421. {
  2422. GlobalSettings = {
  2423. ColorMode = ColorMode.Color,
  2424. Orientation = Orientation.Portrait,
  2425. PaperSize = PaperKind.A4,
  2426. Margins = new MarginSettings() { Top = 10 },
  2427. Out = @"F:\test.pdf",
  2428. },
  2429. Objects = {
  2430. new ObjectSettings()
  2431. {
  2432. Page = "https://teammodelos.blob.core.chinacloudapi.cn/0-public/pie-borderRadius.html",
  2433. },
  2434. }
  2435. };
  2436. _converter.Convert(doc);
  2437. return Ok();
  2438. // return Ok(File(a, "application/octet-stream", "SimplePdf.pdf"));
  2439. }
  2440. catch (Exception ex)
  2441. {
  2442. return BadRequest(new { ex = ex.StackTrace, exmsg = ex.Message });
  2443. }
  2444. }
  2445. //寄送Mail測試
  2446. [HttpPost("test-sendmail")]
  2447. public async Task<IActionResult> TestSendMail(JsonElement json)
  2448. {
  2449. string mail = "jeff@habook.com.tw";
  2450. string tid = "d-833d40ac6397414b852b91e2fa45850a"; //活動報名成功通知模板
  2451. string name = "Jeff";
  2452. string location = "Global";
  2453. await _coreAPIHttpService.SendMail(new Dictionary<string, object> { { "to", mail }, { "tid", tid }, { "vars", new { name = name } } }, location, _configuration);
  2454. return Ok();
  2455. }
  2456. /*
  2457. //自主學習綱領 資料架構測試
  2458. [HttpPost("test-selflearn-structure")]
  2459. public async Task<IActionResult> TestSelfLearnStructure(JsonElement json)
  2460. {
  2461. string tmid = "1595321354";
  2462. ////個人課程
  2463. //主體
  2464. SelfLearn selfLearnT = new SelfLearn();
  2465. selfLearnT.code = $"SelfLearn-{tmid}";
  2466. selfLearnT.id = "a6dc752f-7cae-44a5-9b7b-92cfe71cea14";
  2467. selfLearnT.scope = "private";
  2468. selfLearnT.name = "測試課程課綱";
  2469. selfLearnT.course = new IdName();
  2470. selfLearnT.course.id = "ae64e6a4-54f3-10df-a7f3-79dbe252d295";
  2471. selfLearnT.course.name = "測試課程001";
  2472. selfLearnT.creatorId = $"{tmid}";
  2473. selfLearnT.creatorName = "Miss Lo";
  2474. selfLearnT.release = true;
  2475. selfLearnT.groupLists.Add(new IdName { id = "a986bf87-da87-4bd3-bd90-19ee9fd52836", name = "測試課程名單" });
  2476. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(selfLearnT);
  2477. //節點:章節
  2478. SelfLearnNode selfLearnNodeTChapter = new SelfLearnNode();
  2479. selfLearnNodeTChapter.code = $"SelfLearn-{tmid}";
  2480. selfLearnNodeTChapter.id = "0990cbb6-3228-41d0-aeb0-62209f37dc0d";
  2481. selfLearnNodeTChapter.name = "第一章節";
  2482. selfLearnNodeTChapter.selfLearnId = selfLearnT.id;
  2483. selfLearnNodeTChapter.nodeType = "chapter";
  2484. selfLearnNodeTChapter.openType = "order";
  2485. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(selfLearnNodeTChapter);
  2486. //節點:項目
  2487. SelfLearnNode selfLearnNodeTContent = new SelfLearnNode();
  2488. selfLearnNodeTContent.code = $"SelfLearn-{tmid}";
  2489. selfLearnNodeTContent.id = "5627184f-e9b4-4ceb-a1d0-47727db569b1";
  2490. selfLearnNodeTContent.name = "四則運算";
  2491. selfLearnNodeTContent.selfLearnId = selfLearnT.id;
  2492. selfLearnNodeTContent.selfLearnNodeId = selfLearnNodeTChapter.id;
  2493. selfLearnNodeTContent.nodeType = "content";
  2494. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(selfLearnNodeTContent);
  2495. //內容:作業
  2496. SelfLearnContentHomework selfLearnTContentHomework = new SelfLearnContentHomework();
  2497. selfLearnTContentHomework.code = $"SelfLearn-{tmid}";
  2498. //內容:評量
  2499. SelfLearnContentExam selfLearnTContentExam = new SelfLearnContentExam();
  2500. selfLearnTContentExam.code = $"SelfLearn-{tmid}";
  2501. selfLearnTContentExam.id = "07e6fdd2-6083-4eb6-ac6d-06421edb0b48";
  2502. selfLearnTContentExam.name = "隨堂測驗1";
  2503. selfLearnTContentExam.selfLearnId = selfLearnT.id;
  2504. selfLearnTContentExam.selfLearnNodeId = selfLearnNodeTContent.id;
  2505. selfLearnTContentExam.contentType = "exam";
  2506. //自主課綱的試卷需要從試題庫拷貝到課綱Blob之下 容器:個人課綱:{個人ID} 路徑:selflearn/{selfLearn本體ID}/paper/{試卷名稱}/{試卷各個檔案}
  2507. ////自主課綱Blob需納管入Blob容量計算系統之下
  2508. List<Dictionary<string, string>> sourcePaperDic = new List<Dictionary<string, string>>();
  2509. sourcePaperDic.Add(new Dictionary<string, string>() { { "id", "184914dd-05e0-04f4-e14a-cfce53545018" }, { "blobContainer", "1595321354" }, { "blob", "paper/個人評量測試卷1" }, { "name", "個人評量測試卷1" } });
  2510. foreach (Dictionary<string, string> sourcePaperInfoDic in sourcePaperDic)
  2511. {
  2512. string targetScope = "private";
  2513. var sourceBlobContainer = _azureStorage.GetBlobContainerClient(sourcePaperInfoDic["blobContainer"]);
  2514. string sourceBlobPath = (!sourcePaperInfoDic["blob"].EndsWith("/")) ? sourcePaperInfoDic["blob"] + "/" : sourcePaperInfoDic["blob"];
  2515. var destBlobContainer = _azureStorage.GetBlobContainerClient(tmid); //拷貝對象容器
  2516. string destBlobPath = $"/selflearn/{selfLearnT.id}/paper/{sourcePaperInfoDic["name"]}/";
  2517. Azure.Pageable<BlobItem> sourceBlobs = sourceBlobContainer.GetBlobs(prefix: sourceBlobPath);
  2518. if (sourceBlobs.Count() > 0)
  2519. {
  2520. foreach (var blob in sourceBlobs)
  2521. {
  2522. var sourceFileBlob = sourceBlobContainer.GetBlobClient(blob.Name);
  2523. if (sourceFileBlob.Exists())
  2524. {
  2525. var sourceFileUri = sourceBlobContainer.GetBlobClient(blob.Name).Uri;
  2526. string fileName = blob.Name.Replace(sourceBlobPath, "");
  2527. string destBlobFilePath = $"{destBlobPath}{fileName}";
  2528. await destBlobContainer.GetBlobClient(destBlobFilePath).StartCopyFromUriAsync(sourceFileUri);
  2529. }
  2530. }
  2531. }
  2532. }
  2533. //內容:評量 DB操作
  2534. PaperSimple paper = new PaperSimple()
  2535. {
  2536. id = "184914dd-05e0-04f4-e14a-cfce53545018",
  2537. subjectId = null,
  2538. code = "Paper-1595321354",
  2539. name = "個人評量測試卷1",
  2540. blob = $"/selflearn/{selfLearnT.id}/paper/個人評量測試卷1/",
  2541. scope = "private",
  2542. multipleRule = 1,
  2543. point = new List<double>() { 50, 50 }, //這裡和題庫的格式不同,需要轉換
  2544. answers = new List<List<string>>() { new List<string>() { "B" }, new List<string>() { "A" } }, //這裡和題庫的格式不同,需要轉換
  2545. type = new List<string>() { "single", "single" }, //這裡和題庫的格式不同,需要轉換
  2546. field = new List<int>() { 1, 1 } //認知層次 這裡須由各題的Blob中取得後轉換
  2547. };
  2548. paper.subjectId = selfLearnT.course.id;
  2549. ExamInfo examT = new ExamInfo();
  2550. examT.pk = "Exam";
  2551. examT.scope = "private";
  2552. examT.owner = "teacher";
  2553. examT.code = $"Exam-{tmid}";
  2554. examT.creatorId = $"{tmid}";
  2555. examT.name = "隨堂測驗1";
  2556. examT.papers.Add(paper);
  2557. selfLearnTContentExam.examInfo = examT;
  2558. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(selfLearnTContentExam);
  2559. ////學校課程
  2560. //主體
  2561. SelfLearn selfLearnS = new SelfLearn();
  2562. selfLearnS.pk = "SelfLearn";
  2563. selfLearnS.code = $"SelfLearn-{tmid}";
  2564. selfLearnS.id = "f05f79f2-c58d-4e27-8214-48385e2ac3cd";
  2565. selfLearnS.scope = "private";
  2566. selfLearnS.school = "hbgl";
  2567. selfLearnS.name = "數學一年級上學期課綱";
  2568. selfLearnS.subject = new IdName();
  2569. selfLearnS.subject.id = "c5f96ea0-e65c-f15c-dc59-410da564c185";
  2570. selfLearnS.subject.name = "數學";
  2571. selfLearnS.period = new IdName();
  2572. selfLearnS.period.id = "127e71a7-0ca8-82b8-476b-5269b78066f7";
  2573. selfLearnS.period.name = "測試國中";
  2574. selfLearnS.course = new IdName();
  2575. selfLearnS.course.id = "0d4fa541-ad4f-bee1-c604-764275f6d10e";
  2576. selfLearnS.course.name = "數學一";
  2577. selfLearnS.creatorId = $"{tmid}";
  2578. selfLearnS.creatorName = "Miss Lo";
  2579. selfLearnS.release = true;
  2580. selfLearnS.classes.Add(new IdName { id = "d3090c56-21de-4cc8-a962-a7e7eaa2e913", name = "2023年A班" });
  2581. selfLearnS.groupLists.Add(new IdName { id = "54a39ec1-be0b-43cd-a978-f3133552f291", name = "七年A班" });
  2582. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(selfLearnS);
  2583. //節點:章節
  2584. SelfLearnNode selfLearnNodeSChapter = new SelfLearnNode();
  2585. selfLearnNodeSChapter.code = $"SelfLearn-{tmid}";
  2586. selfLearnNodeSChapter.id = "77172663-aa17-44c6-8259-61870c44121f";
  2587. selfLearnNodeSChapter.name = "第一章節";
  2588. selfLearnNodeSChapter.selfLearnId = selfLearnS.id;
  2589. selfLearnNodeSChapter.nodeType = "chapter";
  2590. selfLearnNodeSChapter.openType = "order";
  2591. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(selfLearnNodeSChapter);
  2592. //節點:項目
  2593. SelfLearnNode selfLearnNodeSContent = new SelfLearnNode();
  2594. selfLearnNodeSContent.code = $"SelfLearn-{tmid}";
  2595. selfLearnNodeSContent.id = "f28c6ecd-38a6-4edb-9160-363a116b8c3b";
  2596. selfLearnNodeSContent.name = "四則運算";
  2597. selfLearnNodeSContent.selfLearnId = selfLearnS.id;
  2598. selfLearnNodeSContent.selfLearnNodeId = selfLearnNodeSChapter.id;
  2599. selfLearnNodeSContent.nodeType = "content";
  2600. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(selfLearnNodeSContent);
  2601. //內容:作業
  2602. SelfLearnContentHomework selfLearnSContentHomework = new SelfLearnContentHomework();
  2603. selfLearnSContentHomework.code = $"SelfLearn-{tmid}";
  2604. //內容:評量
  2605. SelfLearnContentExam selfLearnSContentExam = new SelfLearnContentExam();
  2606. selfLearnSContentExam.code = $"SelfLearn-{tmid}";
  2607. selfLearnSContentExam.id = "3f088f49-fefa-4af5-a324-c577ffb6d1f8";
  2608. selfLearnSContentExam.name = "隨堂測驗1";
  2609. selfLearnSContentExam.selfLearnId = selfLearnS.id;
  2610. selfLearnSContentExam.selfLearnNodeId = selfLearnNodeSContent.id;
  2611. selfLearnSContentExam.contentType = "exam";
  2612. //自主課綱試卷拷貝到課綱
  2613. foreach (Dictionary<string, string> sourcePaperInfoDic in sourcePaperDic)
  2614. {
  2615. string targetScope = "private";
  2616. var sourceBlobContainer = _azureStorage.GetBlobContainerClient(sourcePaperInfoDic["blobContainer"]);
  2617. string sourceBlobPath = (!sourcePaperInfoDic["blob"].EndsWith("/")) ? sourcePaperInfoDic["blob"] + "/" : sourcePaperInfoDic["blob"];
  2618. var destBlobContainer = _azureStorage.GetBlobContainerClient(tmid); //拷貝對象容器
  2619. string destBlobPath = $"/selflearn/{selfLearnS.id}/paper/{sourcePaperInfoDic["name"]}/";
  2620. Azure.Pageable<BlobItem> sourceBlobs = sourceBlobContainer.GetBlobs(prefix: sourceBlobPath);
  2621. if (sourceBlobs.Count() > 0)
  2622. {
  2623. foreach (var blob in sourceBlobs)
  2624. {
  2625. var sourceFileBlob = sourceBlobContainer.GetBlobClient(blob.Name);
  2626. if (sourceFileBlob.Exists())
  2627. {
  2628. var sourceFileUri = sourceBlobContainer.GetBlobClient(blob.Name).Uri;
  2629. string fileName = blob.Name.Replace(sourceBlobPath, "");
  2630. string destBlobFilePath = $"{destBlobPath}{fileName}";
  2631. await destBlobContainer.GetBlobClient(destBlobFilePath).StartCopyFromUriAsync(sourceFileUri);
  2632. }
  2633. }
  2634. }
  2635. }
  2636. paper.blob = $"/selflearn/{selfLearnS.id}/paper/個人評量測試卷1/";
  2637. ExamInfo examS = new ExamInfo();
  2638. examS.pk = "Exam";
  2639. examS.scope = "school";
  2640. examS.owner = "teacher";
  2641. examS.code = $"Exam-{tmid}";
  2642. examS.creatorId = $"{tmid}";
  2643. examS.name = "隨堂測驗1";
  2644. examS.papers.Add(paper);
  2645. selfLearnSContentExam.examInfo = examS;
  2646. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(selfLearnSContentExam);
  2647. return Ok();
  2648. }
  2649. //自主學習綱領 生成評量架構測試
  2650. [HttpPost("test-selflearn-create-exam")]
  2651. public async void TestSelfLearnCreateExam(JsonElement json)
  2652. {
  2653. //輸入項:startTime (-1 會以現在時間記入)
  2654. long startTime = (json.TryGetProperty("startTime", out JsonElement startTimeJ)) ? startTimeJ.GetInt64() : -1;
  2655. var client = _azureCosmos.GetCosmosClient();
  2656. string tmid = "1595321354";
  2657. long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  2658. string code = string.Empty;
  2659. string selfLearnContentExamId = string.Empty;
  2660. SelfLearn selfLearn = new SelfLearn();
  2661. SelfLearnContentExam contentExam = new SelfLearnContentExam();
  2662. //[個人評量學校課程]
  2663. code = $"SelfLearn-{tmid}";
  2664. selfLearnContentExamId = "3f088f49-fefa-4af5-a324-c577ffb6d1f8"; //個人評量學校班級
  2665. contentExam = await client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<SelfLearnContentExam>(selfLearnContentExamId, new PartitionKey(code));
  2666. if (contentExam != null)
  2667. {
  2668. string selfLearnId = contentExam.selfLearnId;
  2669. selfLearn = await client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<SelfLearn>(selfLearnId, new PartitionKey(code));
  2670. }
  2671. if (!string.IsNullOrWhiteSpace(selfLearn.id))
  2672. {
  2673. //評量的架構只能生成 編制班(複數班) OR 選課班(複數班) 擇一,如果同步對象有編制班也有選課班,需生成兩個評量活動
  2674. int examCount = 0;
  2675. if (selfLearn.classes.Count > 0) examCount++;
  2676. if (selfLearn.groupLists.Count > 0) examCount++;
  2677. List<string> actExamInfoId = new List<string>() { "dbdcddc5-a79e-400f-a0b9-42801b176c21", "0c02b5e7-1aea-4126-b872-10baa2b4db56" };
  2678. for (int i = 0; i < examCount; i++)
  2679. {
  2680. string contentExamJsonStr = System.Text.Json.JsonSerializer.Serialize<ExamInfo>(contentExam.examInfo);
  2681. ExamInfo actExamInfo = System.Text.Json.JsonSerializer.Deserialize<ExamInfo>(contentExamJsonStr); //要生成的Exam
  2682. actExamInfo.id = actExamInfoId[i]; //假設每次生成新的評量;實作的時候應該在Exam埋入自主課綱相關的ID,如果可取得此ID的評量則更新
  2683. actExamInfo.source = "0"; //目前先設定為"線上評量",實際上應讓老師選擇
  2684. actExamInfo.creatorId = tmid;
  2685. actExamInfo.year = DateTimeOffset.UtcNow.Year;
  2686. IdName selfLearnSubject = selfLearn.subject;
  2687. IdName selfLearnCourse = selfLearn.course;
  2688. IdName selfLearnPeriod = selfLearn.period;
  2689. if (contentExam.examInfo.scope.Equals("school")) //學校 編制班、選課班 ※編制班、選課班無法共存只能擇一
  2690. {
  2691. actExamInfo.school = selfLearn.school;
  2692. actExamInfo.period.id = selfLearnPeriod.id;
  2693. actExamInfo.period.name = selfLearnPeriod.name;
  2694. actExamInfo.subjects.Add(new ExamSubject() { id = selfLearnSubject.id, name = selfLearnSubject.name });
  2695. if (actExamInfo.id.Equals("dbdcddc5-a79e-400f-a0b9-42801b176c21")) //編制班
  2696. {
  2697. foreach (IdName classRow in selfLearn.classes)
  2698. {
  2699. actExamInfo.classes.Add(classRow.id);
  2700. List<string> targetRow = new List<string>() { $"{selfLearn.course.id}", "class", classRow.id };
  2701. actExamInfo.targets.Add(System.Text.Json.JsonSerializer.SerializeToElement(targetRow));
  2702. }
  2703. }
  2704. else if (actExamInfo.id.Equals("0c02b5e7-1aea-4126-b872-10baa2b4db56")) //選課班
  2705. {
  2706. foreach (IdName groupRow in selfLearn.groupLists)
  2707. {
  2708. actExamInfo.stuLists.Add(groupRow.id);
  2709. List<string> targetRow = new List<string>() { $"{selfLearn.course.id}", "teach", groupRow.id };
  2710. actExamInfo.targets.Add(System.Text.Json.JsonSerializer.SerializeToElement(targetRow));
  2711. }
  2712. }
  2713. }
  2714. else if (contentExam.examInfo.scope.Equals("private"))
  2715. {
  2716. foreach (IdName groupRow in selfLearn.groupLists)
  2717. {
  2718. actExamInfo.subjects.Add(new ExamSubject() { id = selfLearn.course.id, name = selfLearn.course.name });
  2719. actExamInfo.stuLists.Add(groupRow.id);
  2720. List<string> targetRow = new List<string>() { $"{selfLearn.course.id}", groupRow.id };
  2721. actExamInfo.targets.Add(System.Text.Json.JsonSerializer.SerializeToElement(targetRow));
  2722. }
  2723. }
  2724. //以下是Blob拷貝程序
  2725. //ExamInfo內容取得、調整
  2726. //※規則 owner:"school" => 校園評測 "teacher" => 個人評測
  2727. //※規則 scope:"school" => 校本班級 "private" => 個人班級
  2728. //※規則 BLOB容器: scope:"school" => {學校ID}下 scope:"private" => {個人ID}下
  2729. //試卷情報字典
  2730. string paperSubjectId = actExamInfo.subjects.First().id;
  2731. List<Dictionary<string, string>> sourcePaperInfo = new List<Dictionary<string, string>>();
  2732. foreach (PaperSimple paperInfo in contentExam.examInfo.papers)
  2733. {
  2734. string paperBlobPath = (!paperInfo.blob.EndsWith("/")) ? paperInfo.blob + "/" : paperInfo.blob;
  2735. paperBlobPath = (paperInfo.blob.StartsWith("/")) ? paperBlobPath.Remove(0, 1) : paperBlobPath;
  2736. string paperBlobContainer = tmid;
  2737. sourcePaperInfo.Add(new Dictionary<string, string>() { { "id", paperInfo.id }, { "blobContainer", paperBlobContainer }, { "subjectId", paperSubjectId }, { "blob", paperBlobPath } });
  2738. }
  2739. //取得自主課綱下的試卷資料(blob)、複製到評測紀錄下
  2740. //Blob搬運
  2741. int paperIndex = 0;
  2742. foreach (Dictionary<string, string> recordPaperInfoDic in sourcePaperInfo)
  2743. {
  2744. string targetScope = actExamInfo.scope; //評測對象 school:校本班級 private:私人課程
  2745. var sourceBlobContainer = _azureStorage.GetBlobContainerClient(recordPaperInfoDic["blobContainer"]);
  2746. string sourceBlobPath = recordPaperInfoDic["blob"];
  2747. string destBlobContainerId = (!string.IsNullOrWhiteSpace(actExamInfo.school) && actExamInfo.scope.Equals("school")) ? actExamInfo.school : actExamInfo.creatorId;
  2748. var destBlobContainer = _azureStorage.GetBlobContainerClient(destBlobContainerId); //拷貝對象容器
  2749. string destBlobPath = $"exam/{actExamInfo.id}/paper/{recordPaperInfoDic["subjectId"]}"; //拷貝對象路徑 path:exam/{評測ID}/paper/{subjectID}/ ※2022-1-6 式樣變更[原]/paper/{試卷ID}/ [新]/paper/{subjectID}/
  2750. Azure.Pageable<BlobItem> sourceBlobs = sourceBlobContainer.GetBlobs(prefix: sourceBlobPath);
  2751. if (sourceBlobs.Count() > 0)
  2752. {
  2753. foreach (var blob in sourceBlobs)
  2754. {
  2755. var sourceFileBlob = sourceBlobContainer.GetBlobClient(blob.Name);
  2756. if (sourceFileBlob.Exists())
  2757. {
  2758. var sourceFileUri = sourceBlobContainer.GetBlobClient(blob.Name).Uri;
  2759. string fileName = blob.Name.Replace(sourceBlobPath, "");
  2760. string destBlobFilePath = $"{destBlobPath}/{fileName}";
  2761. await destBlobContainer.GetBlobClient(destBlobFilePath).StartCopyFromUriAsync(sourceFileUri);
  2762. }
  2763. }
  2764. }
  2765. actExamInfo.papers[paperIndex].blob = destBlobPath;
  2766. actExamInfo.papers[paperIndex].subjectId = selfLearnSubject.id;
  2767. paperIndex++;
  2768. }
  2769. //以下是ExamController生成評量邏輯
  2770. actExamInfo.createTime = now;
  2771. actExamInfo.startTime = startTime;
  2772. if (actExamInfo.startTime <= 0) actExamInfo.startTime = now;
  2773. actExamInfo.endTime = actExamInfo.startTime + 172800000; //結束時間設為2天後 ※實際上應由老師設定
  2774. List<string> classes = ExamService.getClasses(actExamInfo.classes, actExamInfo.stuLists);
  2775. (List<RMember> tchList, List<RGroupList> classLists) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, classes, selfLearn.school);
  2776. actExamInfo.stuCount = tchList.Count;
  2777. actExamInfo.progress = (actExamInfo.startTime > now) ? "pending" : "going";
  2778. var messageBlob = new ServiceBusMessage();
  2779. if (actExamInfo.scope.Equals("school"))
  2780. {
  2781. actExamInfo.size = await _azureStorage.GetBlobContainerClient(actExamInfo.school).GetBlobsSize($"exam/{actExamInfo.id}");
  2782. await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"exam", name = actExamInfo.school }, _serviceBus, _configuration, _azureRedis);
  2783. }
  2784. else
  2785. {
  2786. string schoolId = string.Empty; //看學生是否有屬於學校,如果有則填入學校ID
  2787. foreach (RMember stuInfo in tchList)
  2788. {
  2789. if (!string.IsNullOrWhiteSpace(stuInfo.schoolId) && string.IsNullOrWhiteSpace(schoolId)) schoolId = stuInfo.schoolId;
  2790. }
  2791. actExamInfo.school = (!string.IsNullOrWhiteSpace(schoolId)) ? schoolId : "SYSTEM_NO_SCHOOL";
  2792. actExamInfo.size = await _azureStorage.GetBlobContainerClient(actExamInfo.creatorId).GetBlobsSize($"exam/{actExamInfo.id}");
  2793. await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"exam", name = actExamInfo.creatorId }, _serviceBus, _configuration, _azureRedis);
  2794. }
  2795. int n = 0;
  2796. List<string> sheetIds = new List<string>();
  2797. foreach (PaperSimple simple in actExamInfo.papers)
  2798. {
  2799. simple.blob = $"/exam/{actExamInfo.id}/paper/{actExamInfo.subjects[n].id}";
  2800. n++;
  2801. simple.sheet = null;
  2802. }
  2803. ExamInfo exam = await client.GetContainer(Constant.TEAMModelOS, "Common").UpsertItemAsync(actExamInfo, new PartitionKey($"{actExamInfo.code}"));
  2804. await BIStats.SetTypeAddStats(client, _dingDing, exam.school, "Exam", 1);//BI统计增/减量
  2805. }
  2806. }
  2807. //[個人評量個人課程]
  2808. //取得自主學習綱領內容、自主學習綱領主體
  2809. code = $"SelfLearn-{tmid}";
  2810. selfLearnContentExamId = "07e6fdd2-6083-4eb6-ac6d-06421edb0b48"; //個人評量個人課程
  2811. contentExam = await client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<SelfLearnContentExam>(selfLearnContentExamId, new PartitionKey(code));
  2812. if (contentExam != null)
  2813. {
  2814. string selfLearnId = contentExam.selfLearnId;
  2815. selfLearn = await client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<SelfLearn>(selfLearnId, new PartitionKey(code));
  2816. }
  2817. if(!string.IsNullOrWhiteSpace(selfLearn.id))
  2818. {
  2819. //補足實體化需要項目
  2820. //targets.row:
  2821. //個人課程: [0]:課程ID(CourseBase.id)[1]stuListId(GroupList.id)
  2822. //學校課程 編制班[0]:課程ID(CourseBase.id)[1]"class"[2]classId
  2823. //學校課程 選課班[0]:課程ID(CourseBase.id)[1]"teach"[2]stuListId(GroupList.id)
  2824. string contentExamJsonStr = System.Text.Json.JsonSerializer.Serialize<ExamInfo>(contentExam.examInfo);
  2825. ExamInfo actExamInfo = System.Text.Json.JsonSerializer.Deserialize<ExamInfo>(contentExamJsonStr); //要生成的Exam
  2826. actExamInfo.id = "78c4232d-b716-40a7-9901-c85b73da79a2"; //假設每次生成新的評量;實作的時候應該在Exam埋入自主課綱相關的ID,如果可取得此ID的評量則更新
  2827. actExamInfo.source = "0"; //目前先設定為"線上評量",實際上應讓老師選擇
  2828. actExamInfo.creatorId = tmid;
  2829. actExamInfo.year = DateTimeOffset.UtcNow.Year;
  2830. IdName selfLearnSubject = selfLearn.subject;
  2831. IdName selfLearnCourse = selfLearn.course;
  2832. IdName selfLearnPeriod = selfLearn.period;
  2833. if (contentExam.examInfo.scope.Equals("school")) //學校 編制班、選課班
  2834. {
  2835. actExamInfo.school = selfLearn.school;
  2836. actExamInfo.period.id = selfLearnPeriod.id;
  2837. actExamInfo.period.name = selfLearnPeriod.name;
  2838. actExamInfo.subjects.Add(new ExamSubject() { id = selfLearnSubject.id, name = selfLearnSubject.name });
  2839. foreach(IdName classRow in selfLearn.classes)
  2840. {
  2841. actExamInfo.classes.Add(classRow.id);
  2842. List<string> targetRow = new List<string>() { $"{selfLearn.course.id}", "class", classRow.id };
  2843. actExamInfo.targets.Add(System.Text.Json.JsonSerializer.SerializeToElement(targetRow));
  2844. }
  2845. foreach (IdName groupRow in selfLearn.groupLists)
  2846. {
  2847. actExamInfo.stuLists.Add(groupRow.id);
  2848. List<string> targetRow = new List<string>() { $"{selfLearn.course.id}", "teach", groupRow.id };
  2849. actExamInfo.targets.Add(System.Text.Json.JsonSerializer.SerializeToElement(targetRow));
  2850. }
  2851. }
  2852. else if(contentExam.examInfo.scope.Equals("private"))
  2853. {
  2854. foreach (IdName groupRow in selfLearn.groupLists)
  2855. {
  2856. actExamInfo.subjects.Add(new ExamSubject() { id = selfLearn.course.id, name = selfLearn.course.name });
  2857. actExamInfo.stuLists.Add(groupRow.id);
  2858. List<string> targetRow = new List<string>() { $"{selfLearn.course.id}", groupRow.id };
  2859. actExamInfo.targets.Add(System.Text.Json.JsonSerializer.SerializeToElement(targetRow));
  2860. }
  2861. }
  2862. //以下是Blob拷貝程序
  2863. //ExamInfo內容取得、調整
  2864. //※規則 owner:"school" => 校園評測 "teacher" => 個人評測
  2865. //※規則 scope:"school" => 校本班級 "private" => 個人班級
  2866. //※規則 BLOB容器: scope:"school" => {學校ID}下 scope:"private" => {個人ID}下
  2867. //試卷情報字典
  2868. string paperSubjectId = actExamInfo.subjects.First().id;
  2869. List <Dictionary<string, string>> sourcePaperInfo = new List<Dictionary<string, string>>();
  2870. foreach (PaperSimple paperInfo in contentExam.examInfo.papers)
  2871. {
  2872. string paperBlobPath = (!paperInfo.blob.EndsWith("/")) ? paperInfo.blob + "/" : paperInfo.blob;
  2873. paperBlobPath = (paperInfo.blob.StartsWith("/")) ? paperBlobPath.Remove(0, 1) : paperBlobPath;
  2874. string paperBlobContainer = tmid;
  2875. sourcePaperInfo.Add(new Dictionary<string, string>() { { "id", paperInfo.id }, { "blobContainer", paperBlobContainer }, { "subjectId", paperSubjectId }, { "blob", paperBlobPath } });
  2876. }
  2877. //取得自主課綱下的試卷資料(blob)、複製到評測紀錄下
  2878. //Blob搬運
  2879. int paperIndex = 0;
  2880. foreach (Dictionary<string, string> recordPaperInfoDic in sourcePaperInfo)
  2881. {
  2882. string targetScope = actExamInfo.scope; //評測對象 school:校本班級 private:私人課程
  2883. var sourceBlobContainer = _azureStorage.GetBlobContainerClient(recordPaperInfoDic["blobContainer"]);
  2884. string sourceBlobPath = recordPaperInfoDic["blob"];
  2885. string destBlobContainerId = (!string.IsNullOrWhiteSpace(actExamInfo.school) && actExamInfo.scope.Equals("school")) ? actExamInfo.school : actExamInfo.creatorId;
  2886. var destBlobContainer = _azureStorage.GetBlobContainerClient(destBlobContainerId); //拷貝對象容器
  2887. string destBlobPath = $"exam/{actExamInfo.id}/paper/{recordPaperInfoDic["subjectId"]}"; //拷貝對象路徑 path:exam/{評測ID}/paper/{subjectID}/ ※2022-1-6 式樣變更[原]/paper/{試卷ID}/ [新]/paper/{subjectID}/
  2888. Azure.Pageable<BlobItem> sourceBlobs = sourceBlobContainer.GetBlobs(prefix: sourceBlobPath);
  2889. if (sourceBlobs.Count() > 0)
  2890. {
  2891. foreach (var blob in sourceBlobs)
  2892. {
  2893. var sourceFileBlob = sourceBlobContainer.GetBlobClient(blob.Name);
  2894. if (sourceFileBlob.Exists())
  2895. {
  2896. var sourceFileUri = sourceBlobContainer.GetBlobClient(blob.Name).Uri;
  2897. string fileName = blob.Name.Replace(sourceBlobPath, "");
  2898. string destBlobFilePath = $"{destBlobPath}/{fileName}";
  2899. await destBlobContainer.GetBlobClient(destBlobFilePath).StartCopyFromUriAsync(sourceFileUri);
  2900. }
  2901. }
  2902. }
  2903. actExamInfo.papers[paperIndex].blob = destBlobPath;
  2904. actExamInfo.papers[paperIndex].subjectId = selfLearn.course.id;
  2905. paperIndex++;
  2906. }
  2907. //以下是ExamController生成評量邏輯
  2908. actExamInfo.createTime = now;
  2909. actExamInfo.startTime = startTime;
  2910. if (actExamInfo.startTime <= 0) actExamInfo.startTime = now;
  2911. actExamInfo.endTime = actExamInfo.startTime + 172800000; //結束時間設為2天後 ※實際上應由老師設定
  2912. List<string> classes = ExamService.getClasses(actExamInfo.classes, actExamInfo.stuLists);
  2913. (List<RMember> tchList, List<RGroupList> classLists) = await GroupListService.GetMemberByListids(_coreAPIHttpService, client, _dingDing, classes, selfLearn.school);
  2914. actExamInfo.stuCount = tchList.Count;
  2915. actExamInfo.progress = (actExamInfo.startTime > now) ? "pending" : "going";
  2916. var messageBlob = new ServiceBusMessage();
  2917. if (actExamInfo.scope.Equals("school"))
  2918. {
  2919. actExamInfo.size = await _azureStorage.GetBlobContainerClient(actExamInfo.school).GetBlobsSize($"exam/{actExamInfo.id}");
  2920. await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"exam", name = actExamInfo.school }, _serviceBus, _configuration, _azureRedis);
  2921. }
  2922. else
  2923. {
  2924. string schoolId = string.Empty; //看學生是否有屬於學校,如果有則填入學校ID
  2925. foreach (RMember stuInfo in tchList)
  2926. {
  2927. if (!string.IsNullOrWhiteSpace(stuInfo.schoolId) && string.IsNullOrWhiteSpace(schoolId)) schoolId = stuInfo.schoolId;
  2928. }
  2929. actExamInfo.school = (!string.IsNullOrWhiteSpace(schoolId)) ? schoolId: "SYSTEM_NO_SCHOOL";
  2930. actExamInfo.size = await _azureStorage.GetBlobContainerClient(actExamInfo.creatorId).GetBlobsSize($"exam/{actExamInfo.id}");
  2931. await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "insert", root = $"exam", name = actExamInfo.creatorId }, _serviceBus, _configuration, _azureRedis);
  2932. }
  2933. int n = 0;
  2934. List<string> sheetIds = new List<string>();
  2935. foreach (PaperSimple simple in actExamInfo.papers)
  2936. {
  2937. simple.blob = $"/exam/{actExamInfo.id}/paper/{actExamInfo.subjects[n].id}";
  2938. n++;
  2939. simple.sheet = null;
  2940. }
  2941. ExamInfo exam = await client.GetContainer(Constant.TEAMModelOS, "Common").UpsertItemAsync(actExamInfo, new PartitionKey($"{actExamInfo.code}"));
  2942. await BIStats.SetTypeAddStats(client, _dingDing, exam.school, "Exam", 1);//BI统计增/减量
  2943. }
  2944. }
  2945. */
  2946. }
  2947. }