BizCustomizeController.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.Extensions.Configuration;
  4. using TEAMModelOS.SDK.DI;
  5. using TEAMModelOS.SDK;
  6. using TEAMModelOS.Models;
  7. using Microsoft.Extensions.Options;
  8. using System.Threading.Tasks;
  9. using TEAMModelOS.SDK.Models.Dtos;
  10. using TEAMModelOS.SDK.Context.Constant;
  11. using System.Collections.Generic;
  12. using System.Text.Json;
  13. using TEAMModelOS.SDK.Extension;
  14. using TEAMModelOS.Filter;
  15. using TEAMModelOS.SDK.Models;
  16. using Azure.Cosmos;
  17. using TEAMModelOS.SDK.Models.Cosmos.OpenEntity;
  18. using System;
  19. using System.Text;
  20. using Azure.Core;
  21. using DocumentFormat.OpenXml.Spreadsheet;
  22. using TEAMModelOS.SDK.Models.Cosmos.Common;
  23. using DocumentFormat.OpenXml.Office2016.Excel;
  24. using DocumentFormat.OpenXml.Wordprocessing;
  25. using TEAMModelOS.Controllers.Analysis;
  26. using System.Net.Http;
  27. using Microsoft.AspNetCore.Hosting;
  28. namespace TEAMModelOS.Controllers
  29. { /// <summary>
  30. /// 企业定制化接口
  31. /// </summary>
  32. [Route("customize")]
  33. [ApiController]
  34. public class BizCustomizeController : ControllerBase
  35. {
  36. public AzureCosmosFactory _azureCosmos;
  37. private readonly AzureStorageFactory _azureStorage;
  38. private readonly AzureRedisFactory _azureRedis;
  39. private readonly DingDing _dingDing;
  40. private readonly Option _option;
  41. private readonly IConfiguration _configuration;
  42. private readonly CoreAPIHttpService _coreAPIHttpService;
  43. private readonly AzureServiceBusFactory _serviceBus;
  44. private readonly SnowflakeId _snowflakeId;
  45. private readonly IHttpClientFactory _httpClient;
  46. private readonly IWebHostEnvironment _environment;
  47. public BizCustomizeController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, AzureServiceBusFactory serviceBus, DingDing dingDing, CoreAPIHttpService coreAPIHttpService, IOptionsSnapshot<Option> option, IConfiguration configuration, SnowflakeId snowflakeId, IHttpClientFactory httpClient, IWebHostEnvironment hostingEnvironment)
  48. {
  49. _azureCosmos = azureCosmos;
  50. _azureStorage = azureStorage;
  51. _azureRedis = azureRedis;
  52. _dingDing = dingDing;
  53. _option = option?.Value;
  54. _configuration = configuration;
  55. _coreAPIHttpService = coreAPIHttpService;
  56. _serviceBus = serviceBus;
  57. _snowflakeId = snowflakeId;
  58. _httpClient = httpClient;
  59. _environment = hostingEnvironment;
  60. }
  61. //shasdu
  62. #region 杉达公司
  63. /// <summary>
  64. /// 开课或者上传课例信息 是因支持VR/AR的公司(杉达)
  65. /// </summary>
  66. /// <param name="jsonElement"></param>
  67. /// <returns></returns>
  68. [ProducesResponseType(StatusCodes.Status200OK)]
  69. [ProducesResponseType(StatusCodes.Status400BadRequest)]
  70. [ProducesDefaultResponseType]
  71. [HttpPost("create-vrar-lesson-shanda-v2")]
  72. [ApiToken(Auth = "2007", Name = "VR·AR开课/上传课例信息", TName = "VR·AR開課/上傳課例信息", EName = "Start VR·AR lesson/upload VR·AR lesson ", RWN = "W", Limit = false)]
  73. public async Task<IActionResult> CreateVRARLessonShanDaV2(JsonElement jsonElement) {
  74. var (id, school) = HttpContext.GetApiTokenInfo();
  75. VRARLessonRecord lessonRecord= jsonElement.ToObject<VRARLessonRecord>();
  76. return null;
  77. }
  78. /// <summary>
  79. /// 开课或者上传课例信息 是因支持VR/AR的公司(杉达)
  80. /// </summary>
  81. /// <param name="jsonElement"></param>
  82. /// <returns></returns>
  83. [ProducesResponseType(StatusCodes.Status200OK)]
  84. [ProducesResponseType(StatusCodes.Status400BadRequest)]
  85. [ProducesDefaultResponseType]
  86. [HttpPost("create-vrar-lesson-shanda")]
  87. [ApiToken(Auth = "2003", Name = "VR·AR开课/上传课例信息", TName = "VR·AR開課/上傳課例信息", EName = "Start VR·AR lesson/upload VR·AR lesson ", RWN = "W", Limit = false)]
  88. public async Task<IActionResult> CreateVRARLessonShanDa(JsonElement jsonElement)
  89. {
  90. var (id, school) = HttpContext.GetApiTokenInfo();
  91. try
  92. {
  93. jsonElement.TryGetProperty("baseJson", out JsonElement baseJson); //课例基础文件信息json
  94. jsonElement.TryGetProperty("timLineJson", out JsonElement timLineJson); //时间json
  95. jsonElement.TryGetProperty("lessonId", out JsonElement lessonId); //课例id
  96. if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return Ok(new { responseDate = new ResponseData<dynamic>() { code = RespondCode.ParamsError, msg = "tmdId参数错误", data = null } }); //上课人ID
  97. jsonElement.TryGetProperty("tmdName", out JsonElement tmdName); //上课人昵称
  98. jsonElement.TryGetProperty("tmdPicture", out JsonElement tmdpicture); //上课人头像
  99. if (!jsonElement.TryGetProperty("startTime", out JsonElement startTime)) return Ok(new { responseDate = new ResponseData<dynamic>() { code = RespondCode.ParamsError, msg = "startTime参数错误", data = null } }); //开始时间
  100. if (!jsonElement.TryGetProperty("duration", out JsonElement duration)) return Ok(new { responseDate = new ResponseData<dynamic>() { code = RespondCode.ParamsError, msg = "startTime参数错误", data = null } }); //上课时长
  101. jsonElement.TryGetProperty("periodId", out JsonElement periodId); //学段id
  102. jsonElement.TryGetProperty("periodName", out JsonElement periodName); //学段名称
  103. jsonElement.TryGetProperty("groupIds", out JsonElement _groupIds); //名单id
  104. jsonElement.TryGetProperty("groupNames", out JsonElement _groupNames); //名单名称
  105. jsonElement.TryGetProperty("gradeIds", out JsonElement _gradeIds); //年级id
  106. jsonElement.TryGetProperty("gradeNames", out JsonElement _gradeNames); //年级名称
  107. jsonElement.TryGetProperty("subjectId", out JsonElement subjectId); //科目id
  108. jsonElement.TryGetProperty("subjecName", out JsonElement subjecName); //科目名称
  109. jsonElement.TryGetProperty("courseId", out JsonElement courseId); //课程id
  110. jsonElement.TryGetProperty("courseName", out JsonElement courseName); //课程名称
  111. LessonRecord lessonRecord = new();
  112. LessonBase lessonBase = null;
  113. TimeLine timeLine = null;
  114. if (!string.IsNullOrEmpty($"{baseJson}"))
  115. {
  116. lessonBase = baseJson.ToObject<LessonBase>();
  117. lessonRecord.upload = 1;
  118. }
  119. else
  120. lessonRecord.upload = 0;
  121. if (!string.IsNullOrEmpty($"{timLineJson}"))
  122. {
  123. timeLine = timLineJson.ToObject<TimeLine>();
  124. lessonRecord.upload = 1;
  125. }
  126. else
  127. lessonRecord.upload = 0;
  128. List<string> groupIds = new();
  129. List<string> groupNames = new();
  130. List<string> gradeIds = new();
  131. List<string> gradeNames = new();
  132. if (!string.IsNullOrEmpty($"{_groupIds}"))
  133. groupIds = _groupIds.ToObject<List<string>>();
  134. if (!string.IsNullOrEmpty($"{_groupNames}"))
  135. groupNames = _groupNames.ToObject<List<string>>();
  136. if (!string.IsNullOrEmpty($"{_gradeIds}"))
  137. gradeIds = _gradeIds.ToObject<List<string>>();
  138. if (!string.IsNullOrEmpty($"{_gradeNames}"))
  139. gradeNames = _gradeNames.ToObject<List<string>>();
  140. var cosmosClient = _azureCosmos.GetCosmosClient();
  141. string code = $"LessonRecord-{school}";
  142. var resLess = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{lessonId}", new PartitionKey($"{code}"));
  143. if (resLess.Status == 200)
  144. {
  145. JsonDocument jsonD = JsonDocument.Parse(resLess.Content);
  146. lessonRecord = jsonD.RootElement.ToObject<LessonRecord>();
  147. }
  148. else
  149. {
  150. lessonRecord.id = _snowflakeId.NextId().ToString();
  151. lessonRecord.code = code;
  152. }
  153. lessonRecord.tmdid = $"{tmdId}";
  154. lessonRecord.tmdname = $"{tmdName}";
  155. lessonRecord.tmdpicture = $"{tmdpicture}";
  156. lessonRecord.school = school;
  157. lessonRecord.scope = "school";
  158. lessonRecord.startTime = long.Parse($"{startTime}");
  159. lessonRecord.duration = double.Parse($"{duration}");
  160. lessonRecord.periodId = $"{periodId}";
  161. lessonRecord.periodName = $"{periodName}";
  162. lessonRecord.subjectId = $"{subjectId}";
  163. lessonRecord.subjecName = $"{subjecName}";
  164. lessonRecord.courseId = $"{courseId}";
  165. lessonRecord.courseName = $"{courseName}";
  166. lessonRecord.groupIds = groupIds;
  167. lessonRecord.groupNames = groupNames;
  168. lessonRecord.grade = gradeIds;
  169. lessonRecord.gradeName = gradeNames;
  170. if (!string.IsNullOrEmpty($"{baseJson}"))
  171. {
  172. lessonRecord.name = lessonBase.summary.activityName;
  173. lessonRecord.attendCount = lessonBase.summary.attendCount;
  174. lessonRecord.clientCount = lessonBase.summary.clientCount;
  175. lessonRecord.attendRate = lessonBase.summary.attendRate;
  176. lessonRecord.groupCount = lessonBase.summary.groupCount;
  177. lessonRecord.collateTaskCount = lessonBase.summary.collateTaskCount;
  178. lessonRecord.collateCount = lessonBase.summary.collateCount;
  179. lessonRecord.pushCount = lessonBase.summary.pushCount;
  180. lessonRecord.totalPoint = lessonBase.summary.totalPoint;
  181. lessonRecord.examQuizCount = lessonBase.summary.examQuizCount;
  182. lessonRecord.interactionCount = lessonBase.summary.interactionCount;
  183. lessonRecord.examPointRate = lessonBase.summary.examPointRate;
  184. lessonRecord.clientInteractionCount = lessonBase.summary.clientInteractionCount;
  185. lessonRecord.clientInteractionAverge = lessonBase.summary.clientInteractionAverge;
  186. lessonRecord.examCount = lessonBase.summary.examCount;
  187. lessonRecord.totalInteractPoint = lessonBase.summary.totalInteractPoint;
  188. lessonRecord.learningCategory = lessonBase.summary.learningCategory;
  189. lessonRecord.source = 1;
  190. //计算TP灯
  191. {
  192. int T = -1;
  193. int P = -1;
  194. if (lessonRecord.clientInteractionAverge <= 0)
  195. {
  196. T = 0;
  197. }
  198. else if (lessonRecord.clientInteractionAverge >= 1 && lessonRecord.clientInteractionAverge <= 2)
  199. {
  200. T = 1;
  201. }
  202. else
  203. {
  204. T = 2;
  205. }
  206. //if (lessonRecord.examCount > 0)
  207. //{
  208. // //有评测次数大于0则P是直接绿灯
  209. // P = 2;
  210. //}
  211. //else {
  212. //}
  213. int a = lessonRecord.hitaClientCmpCount;
  214. int b = lessonRecord.pushCount;
  215. int c = lessonRecord.examCount;
  216. switch (true)
  217. {
  218. case bool when T == 0:
  219. P = 0;
  220. break;
  221. case bool when T == 1 || T == 2:
  222. if (a == 0 && b == 0 && c == 0)
  223. {
  224. P = 0;
  225. }
  226. else if ((a > 0 && b > 0) || (a > 0 && c > 0) || (b > 0 && c > 0))
  227. {
  228. P = 2;
  229. }
  230. else
  231. {
  232. P = 1;
  233. }
  234. break;
  235. }
  236. lessonRecord.tLevel = T;
  237. lessonRecord.pLevel = P;
  238. }
  239. }
  240. if (resLess.Status == 200)
  241. lessonRecord = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<LessonRecord>(lessonRecord, lessonRecord.id, new PartitionKey($"{code}"));
  242. else
  243. lessonRecord = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<LessonRecord>(lessonRecord, new PartitionKey($"{code}"));
  244. var blobClient = _azureStorage.GetBlobContainerClient(containerName: $"{school}");
  245. if (!string.IsNullOrEmpty($"{baseJson}"))
  246. //保存Basejson文件
  247. await AzureStorageBlobExtensions.UploadFileByContainer(blobClient, lessonBase.ToJsonString(), $"records/{lessonRecord.id}/IES", $"Base.json");
  248. if (!string.IsNullOrEmpty($"{timLineJson}"))
  249. //保存TimeLinejson文件
  250. await AzureStorageBlobExtensions.UploadFileByContainer(blobClient, timeLine.ToJsonString(), $"records/{lessonRecord.id}/IES", $"TimeLine.json");
  251. return Ok(new
  252. {
  253. responseData = new ResponseData<dynamic>()
  254. {
  255. code = RespondCode.Ok,
  256. msg = "成功",
  257. data = new
  258. {
  259. lessonRecord,
  260. analysis = new
  261. {
  262. lessonRecord.id,
  263. lessonRecord.name,
  264. lessonRecord.subjectId,
  265. lessonRecord.courseId,
  266. intIndex = lessonRecord.tLevel,
  267. learning = lessonRecord.pLevel,
  268. atendCnt = lessonRecord.attendCount,
  269. grCnt = lessonRecord.groupCount,
  270. taskCnt = lessonRecord.collateTaskCount,
  271. worksCnt = lessonRecord.collateCount,
  272. pushCnt = lessonRecord.pushCount,
  273. scoreCnt = lessonRecord.totalPoint,
  274. emCnt = lessonRecord.examCount,
  275. intTopicCnt = lessonRecord.interactionCount,
  276. emPct = $"{lessonRecord.examPointRate} %",
  277. stuIntCnt = lessonRecord.clientInteractionCount,
  278. study = new
  279. {
  280. coopCnt = lessonRecord.learningCategory.cooperation,
  281. testCnt = lessonRecord.learningCategory.exam,
  282. intCnt = lessonRecord.learningCategory.interaction,
  283. dCnt = lessonRecord.learningCategory.diffential,
  284. taskCnt = lessonRecord.learningCategory.task,
  285. }
  286. }
  287. }
  288. }
  289. });
  290. }
  291. catch (Exception ex)
  292. {
  293. await _dingDing.SendBotMsg($"OpenApi,{Environment.GetEnvironmentVariable("Option:Location")} BizOverallEducation/UpLessonRec() 参数:bizId:{id},school:{school},json:{jsonElement.ToJsonString()} \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  294. return Ok(new { responseData = new ResponseData<dynamic>() { code = RespondCode.Error, msg = "服务端异常" } });
  295. }
  296. }
  297. /// <summary>
  298. /// 获取学校课例 是因支持VR/AR的公司(杉达)
  299. /// </summary>
  300. /// <param name="jsonElement"></param>
  301. /// <returns></returns>
  302. [ProducesDefaultResponseType]
  303. [HttpPost("get-vrar-lessons")]
  304. [ApiToken(Auth = "2004", Name = "获取学校课例", TName = "獲取學校課例", EName = "Get school lessons", RWN = "R", Limit = false)]
  305. public async Task<IActionResult> GetLesson(JsonElement jsonElement)
  306. {
  307. var (id, school) = HttpContext.GetApiTokenInfo();
  308. jsonElement.TryGetProperty("lessonId", out JsonElement lessId);
  309. var cosmosClient = _azureCosmos.GetCosmosClient();
  310. StringBuilder sql = new("select value(c) from c where c.source=1");
  311. if (!string.IsNullOrEmpty($"{lessId}"))
  312. sql.Append($" and c.id='{lessId}'");
  313. List<OLessonRecord> lessonRecords = new();
  314. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<OLessonRecord>(queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord-{school}") }))
  315. {
  316. lessonRecords.Add(item);
  317. }
  318. return Ok(new { responseData = new ResponseData<dynamic>() { code = RespondCode.Ok, msg = "成功", data = lessonRecords } });
  319. }
  320. /// <summary>
  321. /// 获取学校课例分析结果 是因支持VR/AR的公司(杉达)
  322. /// </summary>
  323. /// <param name="jsonElement"></param>
  324. /// <returns></returns>
  325. [ProducesDefaultResponseType]
  326. [HttpPost("get-vrar-lesson-analysis")]
  327. [ApiToken(Auth = "2006", Name = "获取学校课例", TName = "獲取學校課例", EName = "Get school lessons", RWN = "R", Limit = false)]
  328. public async Task<IActionResult> GetLessonAnslysis(JsonElement jsonElement)
  329. {
  330. var (id, school) = HttpContext.GetApiTokenInfo();
  331. if (!jsonElement.TryGetProperty("lessonId", out JsonElement lessonId)) return Ok(new { responseDate = new ResponseData<dynamic>() { code = RespondCode.ParamsError, msg = "lessId参数错误", data = null } }); //上课人ID ;
  332. var cosmosClient = _azureCosmos.GetCosmosClient();
  333. dynamic analysis = null;
  334. await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: $"select c.id,c.name,c.subjectId,c.courseId,c.tLevel,c.pLevel,c.attendCount,c.groupCount,c.collateTaskCount,c.collateCount,c.pushCount,c.totalPoint,c.examCount,c.interactionCount,c.examPointRate,c.clientInteractionCount,c.learningCategory from c where c.id='{lessonId}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord-{school}") }))
  335. {
  336. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  337. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  338. {
  339. var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
  340. while (accounts.MoveNext())
  341. {
  342. JsonElement account = accounts.Current;
  343. LearningCategory learningCategory = account.GetProperty("learningCategory").ToObject<LearningCategory>();
  344. analysis = new
  345. {
  346. id = account.GetProperty("id").GetString(),
  347. name = account.GetProperty("name").GetString(),
  348. subjectId = account.GetProperty("subjectId").GetString(),
  349. courseId = account.GetProperty("courseId").GetString(),
  350. intIndex = account.GetProperty("tLevel").GetInt64(),
  351. learning = account.GetProperty("pLevel").GetInt64(),
  352. atendCnt = account.GetProperty("attendCount").GetInt64(),
  353. grCnt = account.GetProperty("groupCount").GetInt64(),
  354. taskCnt = account.GetProperty("collateTaskCount").GetInt64(),
  355. worksCnt = account.GetProperty("collateCount").GetInt64(),
  356. pushCnt = account.GetProperty("pushCount").GetInt64(),
  357. scoreCnt = account.GetProperty("totalPoint").GetInt64(),
  358. emCnt = account.GetProperty("examCount").GetInt64(),
  359. intTopicCnt = account.GetProperty("interactionCount").GetInt64(),
  360. emPct = $"{account.GetProperty("examPointRate").GetDouble()} %",
  361. stuIntCnt = account.GetProperty("clientInteractionCount").GetInt64(),
  362. study = new
  363. {
  364. coopCnt = learningCategory.cooperation,
  365. testCnt = learningCategory.exam,
  366. intCnt = learningCategory.interaction,
  367. dCnt = learningCategory.diffential,
  368. taskCnt = learningCategory.task,
  369. }
  370. };
  371. //var ids = account.GetProperty("id").GetString();
  372. //var name = account.GetProperty("name").GetString();
  373. //var intIndex = account.GetProperty("tLevel").GetInt64();
  374. //var learning = account.GetProperty("pLevel").GetInt64();
  375. //var atendCnt = account.GetProperty("attendCount").GetInt64();
  376. //var grCnt = account.GetProperty("groupCount").GetInt64();
  377. //var taskCnt = account.GetProperty("collateTaskCount").GetInt64();
  378. //var worksCnt = account.GetProperty("collateCount").GetInt64();
  379. //var pushCnt = account.GetProperty("pushCount").GetInt64();
  380. //var scoreCnt = account.GetProperty("totalPoint").GetInt64();
  381. //var emCnt = account.GetProperty("examCount").GetInt64();
  382. //var intTopicCnt = account.GetProperty("interactionCount").GetInt64();
  383. //var emPct = $"{account.GetProperty("examPointRate").GetDouble()} %";
  384. //var stuIntCnt = account.GetProperty("clientInteractionCount").GetInt64();
  385. //var study = new
  386. //{
  387. // coopCnt = learningCategory.cooperation,
  388. // testCnt = learningCategory.exam,
  389. // intCnt = learningCategory.interaction,
  390. // dCnt = learningCategory.diffential
  391. //};
  392. }
  393. }
  394. }
  395. return Ok(new { responseData = new ResponseData<dynamic>() { code = RespondCode.Ok, msg = "成功", data = analysis } });
  396. }
  397. [ProducesDefaultResponseType]
  398. [HttpPost("get-analysis-course")]
  399. [ApiToken(Auth = "2008", Name = "分析课列", TName = "结算课列科技应用", EName = "application of accounting technology", RWN = "R", Limit = false)]
  400. public async Task<IActionResult> GetAnalysisCourse(JsonElement json)
  401. {
  402. var (id, school) = HttpContext.GetApiTokenInfo();
  403. var responseData = await OpenApiService.getCourseTechnology(_httpClient, _dingDing, id, school, json,_environment);
  404. return Ok(new { responseData });
  405. }
  406. #endregion
  407. #region 智音公司
  408. /// <summary>
  409. /// 添加/修改学生艺术评测(音乐)答题结果
  410. /// </summary>
  411. /// <param name="jsonElement"></param>
  412. /// <returns></returns>
  413. [ProducesDefaultResponseType]
  414. [HttpPost("upsert-student-score-zhiyin")]
  415. [ApiToken(Auth = "2005", Name = "添加/修改学生艺术评测(音乐)答题结果", TName = "添加/修改學生藝術評測音樂答題結果", EName = "Add/modify the music answer results of student art evaluation", RWN = "W", Limit = false)]
  416. public async Task<IActionResult> SetStudnetScore(JsonElement jsonElement)
  417. {
  418. try {
  419. var (id, school) = HttpContext.GetApiTokenInfo();
  420. if (!jsonElement.TryGetProperty("answer", out JsonElement _answer)) return Ok(new { responseDate = new ResponseData<dynamic>() { code = RespondCode.ParamsError, msg = "answer参数错误", data = null } });
  421. OAnswerUp oAnswer = _answer.ToObject<OAnswerUp>();
  422. string fileId = string.IsNullOrWhiteSpace(oAnswer.thirdAnswerId) ? Guid.NewGuid().ToString() : oAnswer.thirdAnswerId;
  423. fileId = fileId.Replace("::", "--");
  424. await _azureStorage.GetBlobContainerClient("0-public").UploadFileByContainer(jsonElement.ToJsonString(), "zhiyinpush", $"{fileId}.json", true);
  425. StudentArtResult studentArtResult = new();
  426. var cosmosClient = _azureCosmos.GetCosmosClient();
  427. var ids = oAnswer.thirdAnswerId.Split("::");
  428. if (ids.Length == 3)
  429. {
  430. string artId = ids[0];
  431. string taskId = ids[1];
  432. string studentId = ids[2];
  433. var resArt = await cosmosClient.GetContainer(Constant.TEAMModelOS, "Student").ReadItemStreamAsync($"{school}-{studentId}", new PartitionKey($"ArtResult-{artId}"));
  434. if (resArt.Status == 200)
  435. {
  436. JsonDocument jsonD = JsonDocument.Parse(resArt.Content);
  437. studentArtResult = jsonD.RootElement.ToObject<StudentArtResult>();
  438. var temp = studentArtResult.results.Find(f => f.taskId.Equals(taskId));
  439. if (temp == null)
  440. {
  441. temp = new ArtQuotaResult();
  442. temp.subjectId = "subject_music";
  443. temp.subjectName = "音乐";
  444. temp.taskId = taskId;
  445. }
  446. temp.score = oAnswer.score;
  447. //智音数据来源
  448. temp.source = 1;
  449. studentArtResult.zyanswer.questionId = oAnswer.questionId;
  450. studentArtResult.zyanswer.thirdAnswerId = oAnswer.thirdAnswerId;
  451. studentArtResult.zyanswer.score = oAnswer.score;
  452. studentArtResult.zyanswer.detail = oAnswer.detail;
  453. studentArtResult.zyanswer.time = DateTimeOffset.Now.ToUnixTimeMilliseconds();
  454. await cosmosClient.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync<StudentArtResult>(studentArtResult, studentArtResult.id, new PartitionKey(studentArtResult.code));
  455. return Ok(new { responseData = new ResponseData<dynamic>() { code = RespondCode.Ok, msg = "成功", data = oAnswer } });
  456. }
  457. else
  458. {
  459. var client = _azureCosmos.GetCosmosClient();
  460. string rId = string.Format("{0}{1}{2}", school, "-", studentId);
  461. List<string> classIds = new();
  462. List<GroupListGrp> groups = await GroupListService.GetMemberInGroupList(_coreAPIHttpService, client, _dingDing, studentId, 2, school, new List<string> { "class", "teach" });
  463. foreach (var grp in groups)
  464. {
  465. classIds.Add(grp.id);
  466. }
  467. var aresponse = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(artId, new PartitionKey($"Art-{school}"));
  468. if (aresponse.Status == 200)
  469. {
  470. using var json = await JsonDocument.ParseAsync(aresponse.ContentStream);
  471. ArtEvaluation art = json.ToObject<ArtEvaluation>();
  472. var artResult = new StudentArtResult
  473. {
  474. id = rId,
  475. pk = "ArtResult",
  476. code = $"ArtResult-{artId}",
  477. studentId = studentId,
  478. picture = "",
  479. studentName = "",
  480. school = school,
  481. userType = 2,
  482. artId = artId,
  483. classIds = classIds,
  484. };
  485. foreach (var qIds in art.settings)
  486. {
  487. foreach (var task in qIds.task)
  488. {
  489. ArtQuotaResult quotaResult = new()
  490. {
  491. quotaId = qIds.id,
  492. quotaName = qIds.quotaname,
  493. quotaType = (int)task.type,
  494. subjectId = task.subject,
  495. taskId = task.acId
  496. };
  497. if (!string.IsNullOrEmpty(quotaResult.taskId) && quotaResult.taskId.Equals(taskId))
  498. {
  499. quotaResult.subjectId = "subject_music";
  500. quotaResult.subjectName = "音乐";
  501. quotaResult.taskId = taskId;
  502. quotaResult.score = oAnswer.score;
  503. //智音数据来源
  504. quotaResult.source = 1;
  505. }
  506. artResult.results.Add(quotaResult);
  507. }
  508. }
  509. artResult.zyanswer.questionId = oAnswer.questionId;
  510. artResult.zyanswer.thirdAnswerId = oAnswer.thirdAnswerId;
  511. artResult.zyanswer.score = oAnswer.score;
  512. artResult.zyanswer.detail = oAnswer.detail;
  513. await client.GetContainer("TEAMModelOS", "Student").CreateItemAsync(artResult, new PartitionKey($"{artResult.code}"));
  514. return Ok(new { responseData = new ResponseData<dynamic>() { code = RespondCode.Ok, msg = "成功", data = oAnswer } });
  515. }
  516. else
  517. {
  518. return Ok(new { responseData = new ResponseData<dynamic>() { code = RespondCode.ParamsError, msg = "活动已被删除" } });
  519. }
  520. //初始化。
  521. }
  522. }
  523. else
  524. {
  525. return Ok(new { responseDate = new ResponseData<dynamic>() { code = RespondCode.ParamsError, msg = "第三方id错误。", data = null } });
  526. }
  527. } catch (Exception ex) {
  528. await _dingDing.SendBotMsg($"智音数据推送数据已接受\n参数:{jsonElement.ToJsonString()}\n且发生系统异常\n{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
  529. return Ok(new { responseDate = new ResponseData<dynamic>() { code = RespondCode.Error, msg = "系统错误", data = null } });
  530. }
  531. }
  532. #endregion
  533. }
  534. }