ExamController.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using Microsoft.AspNetCore.Mvc;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using TEAMModelOS.Models;
  7. using TEAMModelOS.SDK;
  8. using TEAMModelOS.SDK.DI;
  9. using System.Text.Json;
  10. using TEAMModelOS.SDK.Models;
  11. using TEAMModelOS.SDK.Extension;
  12. using Azure.Cosmos;
  13. using Microsoft.AspNetCore.Http;
  14. using Microsoft.Extensions.Options;
  15. using System.IO;
  16. using System.Dynamic;
  17. using System.Net.Http;
  18. using System.Net;
  19. using Newtonsoft.Json;
  20. using System.Linq;
  21. using StackExchange.Redis;
  22. using static TEAMModelOS.SDK.Models.Teacher;
  23. using Microsoft.Extensions.Configuration;
  24. using TEAMModelOS.Filter;
  25. using Microsoft.AspNetCore.Authorization;
  26. using HTEXLib.COMM.Helpers;
  27. namespace TEAMModelAPI.Controllers
  28. {
  29. [ProducesResponseType(StatusCodes.Status200OK)]
  30. [ProducesResponseType(StatusCodes.Status400BadRequest)]
  31. [ApiController]
  32. [Route("school")]
  33. public class ExamController : ControllerBase
  34. {
  35. public AzureCosmosFactory _azureCosmos;
  36. private readonly AzureStorageFactory _azureStorage;
  37. private readonly AzureRedisFactory _azureRedis;
  38. private readonly DingDing _dingDing;
  39. private readonly Option _option;
  40. private readonly IConfiguration _configuration;
  41. public ExamController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, DingDing dingDing, IOptionsSnapshot<Option> option, IConfiguration configuration)
  42. {
  43. _azureCosmos = azureCosmos;
  44. _azureStorage = azureStorage;
  45. _azureRedis = azureRedis;
  46. _dingDing = dingDing;
  47. _option = option?.Value;
  48. _configuration = configuration;
  49. }
  50. /// <summary>
  51. /// 获取试卷和评测的条件信息
  52. /// </summary>
  53. /// <param name="request"></param>
  54. /// <returns></returns>
  55. [ProducesDefaultResponseType]
  56. [HttpPost("get-paper-exam-condition")]
  57. [ApiToken(Auth = "11", Name = "试卷和评测的条件信息", RW = "R", Limit = false)]
  58. public async Task<IActionResult> GetPaperExamCondition(JsonElement json)
  59. {
  60. json.TryGetProperty("periodId", out JsonElement _periodId);
  61. var (id, school) = HttpContext.GetApiTokenInfo();
  62. School data = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(school, new PartitionKey("Base"));
  63. var exmaType = new { type = new List<string> { "regular", "simulation", "normal" } };//regula ,正规考, simulation 模拟靠考,normal 普通考
  64. var exmaMode = new { type = new List<string> { "0", "1", "2" } };//0 线上评测, 1 课中评测 ,2 阅卷评测
  65. var period= data.period.Find(x => x.id.Equals($"{_periodId}"));
  66. if (period != null)
  67. {
  68. return Ok(new { period.subjects, period.analysis, period.grades , exmaType, exmaMode });
  69. }
  70. else {
  71. return Ok(new { error = 1, msg = "学段不存在!" });
  72. }
  73. }
  74. }
  75. }