|
@@ -16,6 +16,12 @@ using TEAMModelOS.SDK.Models.Cosmos.Student;
|
|
|
using DocumentFormat.OpenXml.Math;
|
|
|
using DocumentFormat.OpenXml.Wordprocessing;
|
|
|
using TEAMModelOS.Filter;
|
|
|
+using TEAMModelOS.SDK.Models;
|
|
|
+using Azure.Cosmos;
|
|
|
+using TEAMModelOS.SDK.Models.Cosmos.OpenEntity;
|
|
|
+using System;
|
|
|
+using Newtonsoft.Json.Linq;
|
|
|
+using System.Text;
|
|
|
|
|
|
namespace TEAMModelOS.Controllers
|
|
|
{
|
|
@@ -34,7 +40,9 @@ namespace TEAMModelOS.Controllers
|
|
|
private readonly IConfiguration _configuration;
|
|
|
private readonly CoreAPIHttpService _coreAPIHttpService;
|
|
|
private readonly AzureServiceBusFactory _serviceBus;
|
|
|
- public BizOverallEducationController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, AzureServiceBusFactory serviceBus, DingDing dingDing, CoreAPIHttpService coreAPIHttpService, IOptionsSnapshot<Option> option, IConfiguration configuration)
|
|
|
+ private readonly SnowflakeId _snowflakeId;
|
|
|
+
|
|
|
+ public BizOverallEducationController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, AzureServiceBusFactory serviceBus, DingDing dingDing, CoreAPIHttpService coreAPIHttpService, IOptionsSnapshot<Option> option, IConfiguration configuration, SnowflakeId snowflakeId)
|
|
|
{
|
|
|
_azureCosmos = azureCosmos;
|
|
|
_azureStorage = azureStorage;
|
|
@@ -44,9 +52,9 @@ namespace TEAMModelOS.Controllers
|
|
|
_configuration = configuration;
|
|
|
_coreAPIHttpService = coreAPIHttpService;
|
|
|
_serviceBus = serviceBus;
|
|
|
+ _snowflakeId = snowflakeId;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/// <summary>
|
|
|
/// 设置学生画像
|
|
|
/// </summary>
|
|
@@ -78,23 +86,173 @@ namespace TEAMModelOS.Controllers
|
|
|
return Ok(new { responseData });
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- public async Task<IActionResult> UpGet(JsonElement jsonElement)
|
|
|
+ /// <summary>
|
|
|
+ /// 开课或者上传课例信息 是因支持VR/AR的公司
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("set-lesson-relord")]
|
|
|
+ [ApiToken(Auth = "1903", Name = "开课/上传课例信息", TName = "開課/上傳課例信息", EName = "Start class/upload class information", RWN = "W", Limit = false)]
|
|
|
+ public async Task<IActionResult> UpLessonRec(JsonElement jsonElement)
|
|
|
{
|
|
|
var (id, school) = HttpContext.GetApiTokenInfo();
|
|
|
- //if(!jsonElement.TryGetProperty("schoolId",out JsonElement schoolId)) return Ok(new { code = RespondCode.ParamsError, msg = "参数错误:schoolId", data = "" });
|
|
|
- //var responseData = await OpenApiService.GetLoginStuInfo(_azureCosmos, _dingDing, _option, id, school, jsonElement);
|
|
|
- jsonElement.TryGetProperty("basejson", out JsonElement basejson);
|
|
|
- jsonElement.TryGetProperty("basejson", out JsonElement tempjson);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ jsonElement.TryGetProperty("baseJson", out JsonElement baseJson); //课例基础文件信息json
|
|
|
+ jsonElement.TryGetProperty("timLineJson", out JsonElement timLineJson); //时间json
|
|
|
+ jsonElement.TryGetProperty("lessId", out JsonElement lessId); //课例id
|
|
|
+ if (!jsonElement.TryGetProperty("tmdId", out JsonElement tmdId)) return Ok(new { responseDate = new ResponseData<dynamic>() { code = RespondCode.ParamsError, msg = "baseJson参数错误", data = null } }); //上课人ID
|
|
|
+ jsonElement.TryGetProperty("tmdName", out JsonElement tmdName); //上课人昵称
|
|
|
+ jsonElement.TryGetProperty("tmdPicture", out JsonElement tmdpicture); //上课人头像
|
|
|
+ if (!jsonElement.TryGetProperty("startTime", out JsonElement startTime)) return Ok(new { responseDate = new ResponseData<dynamic>() { code = RespondCode.ParamsError, msg = "baseJson参数错误", data = null } }); //开始时间
|
|
|
+ if (!jsonElement.TryGetProperty("duration", out JsonElement duration)) return Ok(new { responseDate = new ResponseData<dynamic>() { code = RespondCode.ParamsError, msg = "baseJson参数错误", data = null } }); //上课时长
|
|
|
+ jsonElement.TryGetProperty("periodId", out JsonElement periodId); //学段id
|
|
|
+ jsonElement.TryGetProperty("periodName", out JsonElement periodName); //学段名称
|
|
|
+ jsonElement.TryGetProperty("groupIds", out JsonElement _groupIds); //名单id
|
|
|
+ jsonElement.TryGetProperty("groupNames", out JsonElement _groupNames); //名单名称
|
|
|
+ jsonElement.TryGetProperty("gradeIds", out JsonElement _gradeIds); //年级id
|
|
|
+ jsonElement.TryGetProperty("gradeNames", out JsonElement _gradeNames); //年级名称
|
|
|
+ jsonElement.TryGetProperty("subjectId", out JsonElement subjectId); //科目id
|
|
|
+ jsonElement.TryGetProperty("subjecName", out JsonElement subjecName); //科目名称
|
|
|
+ jsonElement.TryGetProperty("courseId", out JsonElement courseId); //课程id
|
|
|
+ jsonElement.TryGetProperty("courseName", out JsonElement courseName); //课程名称
|
|
|
|
|
|
+ LessonRecord lessonRecord = new();
|
|
|
+ LessonBase lessonBase = null;
|
|
|
+ TimeLine timeLine = null;
|
|
|
+ if (!string.IsNullOrEmpty($"{baseJson}"))
|
|
|
+ {
|
|
|
+ lessonBase = baseJson.ToObject<LessonBase>();
|
|
|
+ lessonRecord.upload = 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ lessonRecord.upload = 0;
|
|
|
+ if (!string.IsNullOrEmpty($"{timLineJson}"))
|
|
|
+ {
|
|
|
+ timeLine = timLineJson.ToObject<TimeLine>();
|
|
|
+ lessonRecord.upload = 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ lessonRecord.upload = 0;
|
|
|
+
|
|
|
+ List<string> groupIds = new();
|
|
|
+ List<string> groupNames = new();
|
|
|
+ List<string> gradeIds = new();
|
|
|
+ List<string> gradeNames = new();
|
|
|
|
|
|
+ if (!string.IsNullOrEmpty($"{_groupIds}"))
|
|
|
+ groupIds = _groupIds.ToObject<List<string>>();
|
|
|
+ if (!string.IsNullOrEmpty($"{_groupNames}"))
|
|
|
+ groupNames = _groupNames.ToObject<List<string>>();
|
|
|
+ if (!string.IsNullOrEmpty($"{_gradeIds}"))
|
|
|
+ gradeIds = _gradeIds.ToObject<List<string>>();
|
|
|
+ if (!string.IsNullOrEmpty($"{_gradeNames}"))
|
|
|
+ gradeNames = _gradeNames.ToObject<List<string>>();
|
|
|
|
|
|
- return Ok(new { responseData = new ResponseData<dynamic>() { code = RespondCode.ParamsError, msg = "idToken参数错误", data = null } });
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
+ string code = $"LessonRecord-{school}";
|
|
|
|
|
|
+ var resLess = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{lessId}", new PartitionKey($"{code}"));
|
|
|
+ if (resLess.Status == 200)
|
|
|
+ {
|
|
|
+ JsonDocument jsonD = JsonDocument.Parse(resLess.Content);
|
|
|
+ lessonRecord = jsonD.RootElement.ToObject<LessonRecord>();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ lessonRecord.id = _snowflakeId.NextId().ToString();
|
|
|
+ lessonRecord.code = code;
|
|
|
+ }
|
|
|
|
|
|
+ lessonRecord.tmdid = $"{tmdId}";
|
|
|
+ lessonRecord.tmdname = $"{tmdName}";
|
|
|
+ lessonRecord.tmdpicture = $"{tmdpicture}";
|
|
|
+ lessonRecord.name = lessonBase.summary.activityName;
|
|
|
+ lessonRecord.school = school;
|
|
|
+ lessonRecord.scope = "school";
|
|
|
+ lessonRecord.startTime = long.Parse($"{startTime}");
|
|
|
+ lessonRecord.duration = double.Parse($"{duration}");
|
|
|
+ lessonRecord.periodId = $"{periodId}";
|
|
|
+ lessonRecord.periodName = $"{periodName}";
|
|
|
+ lessonRecord.subjectId = $"{subjectId}";
|
|
|
+ lessonRecord.subjecName = $"{subjecName}";
|
|
|
+ lessonRecord.courseId = $"{courseId}";
|
|
|
+ lessonRecord.courseName = $"{courseName}";
|
|
|
+ lessonRecord.groupIds = groupIds;
|
|
|
+ lessonRecord.groupNames = groupNames;
|
|
|
+ lessonRecord.grade = gradeIds;
|
|
|
+ lessonRecord.gradeName = gradeNames;
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty($"{baseJson}"))
|
|
|
+ {
|
|
|
+ lessonRecord.attendCount = lessonBase.summary.attendCount;
|
|
|
+ lessonRecord.clientCount = lessonBase.summary.clientCount;
|
|
|
+ lessonRecord.attendRate = lessonBase.summary.attendRate;
|
|
|
+ lessonRecord.groupCount = lessonBase.summary.groupCount;
|
|
|
+ lessonRecord.collateTaskCount = lessonBase.summary.collateTaskCount;
|
|
|
+ lessonRecord.collateCount = lessonBase.summary.collateCount;
|
|
|
+ lessonRecord.pushCount = lessonBase.summary.pushCount;
|
|
|
+ lessonRecord.totalPoint = lessonBase.summary.totalPoint;
|
|
|
+ lessonRecord.examQuizCount = lessonBase.summary.examQuizCount;
|
|
|
+ lessonRecord.interactionCount = lessonBase.summary.interactionCount;
|
|
|
+ lessonRecord.examPointRate = lessonBase.summary.examPointRate;
|
|
|
+ lessonRecord.clientInteractionCount = lessonBase.summary.clientInteractionCount;
|
|
|
+ lessonRecord.clientInteractionAverge = lessonBase.summary.clientInteractionAverge;
|
|
|
+ lessonRecord.examCount = lessonBase.summary.examCount;
|
|
|
+ lessonRecord.totalInteractPoint = lessonBase.summary.totalInteractPoint;
|
|
|
+ lessonRecord.source = 1;
|
|
|
+ }
|
|
|
+ if (resLess.Status == 200)
|
|
|
+ lessonRecord = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<LessonRecord>(lessonRecord, lessonRecord.id, new PartitionKey($"{code}"));
|
|
|
+ else
|
|
|
+ lessonRecord = await cosmosClient.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<LessonRecord>(lessonRecord, new PartitionKey($"{code}"));
|
|
|
+
|
|
|
+ var blobClient = _azureStorage.GetBlobContainerClient(containerName: $"{school}");
|
|
|
+ if (!string.IsNullOrEmpty($"{baseJson}"))
|
|
|
+
|
|
|
+ //保存Basejson文件
|
|
|
+ await AzureStorageBlobExtensions.UploadFileByContainer(blobClient, lessonBase.ToJsonString(), $"records/{lessonRecord.id}/IES", $"Base.json");
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty($"{timLineJson}"))
|
|
|
+ //保存TimeLinejson文件
|
|
|
+ await AzureStorageBlobExtensions.UploadFileByContainer(blobClient, timeLine.ToJsonString(), $"records/{lessonRecord.id}/IES", $"TimeLine.json");
|
|
|
+
|
|
|
+ return Ok(new { responseData = new ResponseData<dynamic>() { code = RespondCode.Ok, msg = "成功", data = lessonRecord } });
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"OpenApi,{Environment.GetEnvironmentVariable("Option:Location")} BizOverallEducation/UpLessonRec() 参数:bizId:{id},school:{school},json:{jsonElement.ToJsonString()} \n {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
|
+ return Ok(new { responseData= new ResponseData<dynamic>() { code = RespondCode.Error, msg = "服务端异常" } });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 获取学校课例
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("get-lesson-relords")]
|
|
|
+ [ApiToken(Auth = "1904", Name = "获取学校课例", TName = "獲取學校課例", EName = "Get school lessons", RWN = "R", Limit = false)]
|
|
|
+ public async Task<IActionResult> GetLessonRec(JsonElement jsonElement)
|
|
|
+ {
|
|
|
+ var (id, school) = HttpContext.GetApiTokenInfo();
|
|
|
+ jsonElement.TryGetProperty("lessId", out JsonElement lessId);
|
|
|
+ var cosmosClient = _azureCosmos.GetCosmosClient();
|
|
|
+
|
|
|
+ StringBuilder sql = new("select value(c) from c where c.source=1");
|
|
|
+ if (!string.IsNullOrEmpty($"{lessId}"))
|
|
|
+ sql.Append($" and c.id='{lessId}'");
|
|
|
+
|
|
|
+ List<OLessonRecord> lessonRecords = new();
|
|
|
+ await foreach (var item in cosmosClient.GetContainer(Constant.TEAMModelOS,"School").GetItemQueryIterator<OLessonRecord>(queryText:sql.ToString(),requestOptions:new QueryRequestOptions() { PartitionKey = new PartitionKey($"LessonRecord-{school}") }))
|
|
|
+ {
|
|
|
+ lessonRecords.Add(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Ok(new { responseData = new ResponseData<dynamic>() { code = RespondCode.Ok, msg = "成功", data = lessonRecords } });
|
|
|
+ }
|
|
|
///数据结构说明
|
|
|
/**
|
|
|
*
|