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