|
@@ -4,6 +4,7 @@ using Microsoft.Azure.Cosmos;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
+using System.Net.Http;
|
|
|
using System.Reflection.Metadata.Ecma335;
|
|
|
using System.Text;
|
|
|
using System.Text.Json;
|
|
@@ -30,7 +31,8 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
/// <param name="type"></param>
|
|
|
/// <param name="azureCosmos"></param>
|
|
|
/// <param name="azureStorage"></param>
|
|
|
- public static async Task<EvaluationSyncInfo> PackageEvaluation( string id,string scope, string ownerId, string type, AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage,CoreAPIHttpService _coreAPIHttpService, DingDing _dingDing)
|
|
|
+ public static async Task<EvaluationSyncInfo> PackageEvaluation( string id,string scope, string ownerId, string type, AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage,
|
|
|
+ CoreAPIHttpService _coreAPIHttpService, DingDing _dingDing, IHttpClientFactory _httpClientFactory)
|
|
|
{
|
|
|
EvaluationSource evaluationSource = new EvaluationSource() { type=type,id=id};
|
|
|
EvaluationSyncInfo evaluationSyncInfo= null;
|
|
@@ -47,18 +49,52 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
string schoolCode = null;
|
|
|
if (scope.Equals("school"))
|
|
|
{
|
|
|
- School school = await azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>(ownerId, new PartitionKey("Base"));
|
|
|
- schoolCode= ownerId;
|
|
|
- evaluationSource.school = school;
|
|
|
- ownerName = school.name;
|
|
|
- ownerPicture = school.picture;
|
|
|
+ try {
|
|
|
+ School school = await azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>(ownerId, new PartitionKey("Base"));
|
|
|
+ schoolCode= ownerId;
|
|
|
+ evaluationSource.school = school;
|
|
|
+ ownerName = school.name;
|
|
|
+ ownerPicture = school.picture;
|
|
|
+ if (!string.IsNullOrWhiteSpace(ownerPicture))
|
|
|
+ {
|
|
|
+ //学校logo 下载到本地、
|
|
|
+ HttpResponseMessage message = await _httpClientFactory.CreateClient().GetAsync(ownerPicture);
|
|
|
+ if (message.IsSuccessStatusCode)
|
|
|
+ {
|
|
|
+ string base64Prefix = "data:image/jpeg;base64,";
|
|
|
+ byte[] fileBytes = await message.Content.ReadAsByteArrayAsync();
|
|
|
+ ownerPicture =$"{base64Prefix}{Convert.ToBase64String(fileBytes)}";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex) {
|
|
|
+ await _dingDing.SendBotMsg($"打包评测数据,获取学校信息报错,{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- Teacher teacher = await azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<Teacher>(ownerId, new PartitionKey("Base"));
|
|
|
- evaluationSource.teacher = teacher;
|
|
|
- ownerName = teacher.name;
|
|
|
- ownerPicture = teacher.picture;
|
|
|
+ try {
|
|
|
+ Teacher teacher = await azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<Teacher>(ownerId, new PartitionKey("Base"));
|
|
|
+ evaluationSource.teacher = teacher;
|
|
|
+ ownerName = teacher.name;
|
|
|
+ ownerPicture = teacher.picture;
|
|
|
+ if (!string.IsNullOrWhiteSpace(ownerPicture))
|
|
|
+ {
|
|
|
+ //学校logo 下载到本地、
|
|
|
+ HttpResponseMessage message = await _httpClientFactory.CreateClient().GetAsync(ownerPicture);
|
|
|
+ if (message.IsSuccessStatusCode)
|
|
|
+ {
|
|
|
+ string base64Prefix = "data:image/jpeg;base64,";
|
|
|
+ byte[] fileBytes = await message.Content.ReadAsByteArrayAsync();
|
|
|
+ ownerPicture =$"{base64Prefix}{Convert.ToBase64String(fileBytes)}";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex) {
|
|
|
+ await _dingDing.SendBotMsg($"打包评测数据,获取教师信息报错,{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|
|
|
var responseEvaluationSyncInfo = await azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).ReadItemStreamAsync(id, new PartitionKey("EvaluationSyncInfo"));
|
|
|
if (responseEvaluationSyncInfo.IsSuccessStatusCode)
|
|
@@ -308,7 +344,7 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
dataStr.Append(evaluationSyncInfo.name);
|
|
|
dataStr.Append(evaluationSyncInfo.type);
|
|
|
dataStr.Append(evaluationSyncInfo.owner);
|
|
|
- dataStr.Append(evaluationSyncInfo.ow);
|
|
|
+ dataStr.Append(evaluationSyncInfo.ownerId);
|
|
|
dataStr.Append(evaluationSyncInfo.scode);
|
|
|
dataStr.Append(evaluationSyncInfo.scope);
|
|
|
dataStr.Append(evaluationSyncInfo.grouplistHash);
|
|
@@ -369,7 +405,7 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
await azureStorage.GetBlobContainerClient(ownerId).UploadFileByContainer(groupListJson, $"package/{id}", "groupList.json");
|
|
|
await azureStorage.GetBlobContainerClient(ownerId).UploadFileByContainer(new { evaluationClient, evaluationExams }.ToJsonString(), $"package/{id}", "evaluation.json");
|
|
|
evaluationSyncInfo.dataSize = dataSize;
|
|
|
- //学校logo 下载到本地、
|
|
|
+
|
|
|
await azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).UpsertItemAsync<EvaluationSyncInfo>(evaluationSyncInfo, new PartitionKey("EvaluationSyncInfo"));
|
|
|
// await azureStorage.GetBlobContainerClient(owner).UploadFileByContainer(evaluationSyncInfo.ToJsonString(), $"package/{id}", "syncinfo.json");
|
|
|
}
|