|
@@ -26,6 +26,8 @@ using Azure.Storage.Blobs.Models;
|
|
|
using System.IO;
|
|
|
using Azure;
|
|
|
using static TEAMModelOS.SDK.Models.Service.LessonService;
|
|
|
+using DinkToPdf.Contracts;
|
|
|
+using TEAMModelOS.SDK.Helper.Common.DateTimeHelper;
|
|
|
|
|
|
namespace TEAMModelOS.FunctionV4.ServiceBus
|
|
|
{
|
|
@@ -40,7 +42,8 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
|
|
|
private readonly NotificationService _notificationService;
|
|
|
private readonly CoreAPIHttpService _coreAPIHttpService;
|
|
|
private readonly IConfiguration _configuration;
|
|
|
- public ActiveTaskTopic(CoreAPIHttpService coreAPIHttpService, AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, AzureServiceBusFactory serviceBus, IOptionsSnapshot<Option> option, NotificationService notificationService, IConfiguration configuration)
|
|
|
+ private readonly IConverter _converter;
|
|
|
+ public ActiveTaskTopic(IConverter converter, CoreAPIHttpService coreAPIHttpService, AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, AzureServiceBusFactory serviceBus, IOptionsSnapshot<Option> option, NotificationService notificationService, IConfiguration configuration)
|
|
|
{
|
|
|
_azureCosmos = azureCosmos;
|
|
|
_dingDing = dingDing;
|
|
@@ -51,6 +54,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
|
|
|
_notificationService = notificationService;
|
|
|
_configuration = configuration;
|
|
|
_coreAPIHttpService = coreAPIHttpService;
|
|
|
+ _converter = converter;
|
|
|
}
|
|
|
[Function("Exam")]
|
|
|
public async Task ExamFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "exam", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
|
|
@@ -601,7 +605,175 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
|
|
|
await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,ItemCond()\n{ex.Message}\n{ex.StackTrace}\n\n{msg}", GroupNames.醍摩豆服務運維群組);
|
|
|
}
|
|
|
}
|
|
|
+ [Function("GenPdf")]
|
|
|
+ public async Task GenPdfFunc([ServiceBusTrigger("%Azure:ServiceBus:GenPdfQueue%", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ /* var jsonMsg = JsonDocument.Parse(msg);
|
|
|
+ jsonMsg.RootElement.TryGetProperty("id", out JsonElement id);
|
|
|
+ //jsonMsg.RootElement.TryGetProperty("code", out JsonElement code);*/
|
|
|
+ List<Study> studies = new();
|
|
|
+ JsonElement element = msg.ToObject<JsonElement>();
|
|
|
+ element.TryGetProperty("id", out JsonElement ids);
|
|
|
+ List<string> tIds = ids.ToObject<List<string>>();
|
|
|
+ element.TryGetProperty("school", out JsonElement code);
|
|
|
+ string sname = string.Empty;
|
|
|
+ var scquery = $"SELECT c.name from c where c.id = '{code}'";
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: scquery, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
|
|
|
+ {
|
|
|
+
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
|
|
|
+ while (accounts.MoveNext())
|
|
|
+ {
|
|
|
+ JsonElement account = accounts.Current;
|
|
|
+ sname = account.GetProperty("name").ToString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ foreach (string id in tIds)
|
|
|
+ {
|
|
|
+ List<(List<string> tch, List<Dictionary<string, List<string>>> groupLists)> tchInfo = new();
|
|
|
+ var query = $"SELECT top 1 c.tchLists,c.groupLists FROM c where array_contains(c.teacIds, '{id}') order by c.createTime desc";
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Study-{code}") }))
|
|
|
+ {
|
|
|
+
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
|
|
|
+ while (accounts.MoveNext())
|
|
|
+ {
|
|
|
+ JsonElement account = accounts.Current;
|
|
|
+ List<string> tchId = new();
|
|
|
+ List<Dictionary<string, List<string>>> groupLists = new();
|
|
|
+ if (account.TryGetProperty("tchLists", out JsonElement tchLists))
|
|
|
+ {
|
|
|
+ tchId = tchLists.ToObject<List<string>>();
|
|
|
+ };
|
|
|
+ if (account.TryGetProperty("groupLists", out JsonElement group))
|
|
|
+ {
|
|
|
+ groupLists = group.ToObject<List<Dictionary<string, List<string>>>>();
|
|
|
+ };
|
|
|
+ tchInfo.Add((tchId, groupLists));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ string cname = string.Empty;
|
|
|
+ string gname = string.Empty;
|
|
|
+ foreach (var (tch, groupLists) in tchInfo)
|
|
|
+ {
|
|
|
+ List<(string pId, List<string> gid)> ps = new List<(string pId, List<string> gid)>();
|
|
|
+ if (groupLists.Count > 0)
|
|
|
+ {
|
|
|
+ var group = groupLists;
|
|
|
+ foreach (var gp in group)
|
|
|
+ {
|
|
|
+ foreach (KeyValuePair<string, List<string>> pp in gp)
|
|
|
+ {
|
|
|
+ ps.Add((pp.Key, pp.Value));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ (List<RMember> tchList, List<RGroupList> classInfos) = await GroupListService.GetStutmdidListids(_coreAPIHttpService, client, _dingDing, tch, code.GetString(), ps);
|
|
|
+ gname = tchList.Where(c => c.id == id).FirstOrDefault().groupName;
|
|
|
+ cname = tchList.Where(c => c.id == id).FirstOrDefault().name;
|
|
|
+ }
|
|
|
+
|
|
|
+ var queryInfo = $"select c.id,c.name,c.type,c.hour,c.startTime,c.endTime,c.presenter,c.topic,c.settings,c.desc from c where (c.status<>404 or IS_DEFINED(c.status) = false and array_contains(c.teacIds, '{id}') )";
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<Study>(queryText: queryInfo, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Study-{code}") }))
|
|
|
+ {
|
|
|
+ studies.Add(item);
|
|
|
+
|
|
|
+ }
|
|
|
+ List<string> details = new();
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
+ foreach (Study study in studies)
|
|
|
+ {
|
|
|
|
|
|
+ var start = DateTimeHelper.FromUnixTimestamp(study.startTime).ToString("yyyy/MM/dd HH:mm:ss");
|
|
|
+ var end = DateTimeHelper.FromUnixTimestamp(study.endTime).ToString("yyyy/MM/dd HH:mm:ss");
|
|
|
+ string tname = string.Empty;
|
|
|
+ List<string> setName = new();
|
|
|
+ foreach (string setting in study.settings)
|
|
|
+ {
|
|
|
+ if (setting.Equals("sign"))
|
|
|
+ {
|
|
|
+ setName.Add("扫码签到");
|
|
|
+ }
|
|
|
+ else if (setting.Equals("hw"))
|
|
|
+ {
|
|
|
+ setName.Add("作业提交");
|
|
|
+ }
|
|
|
+ else if (setting.Equals("survey"))
|
|
|
+ {
|
|
|
+ setName.Add("问卷反馈");
|
|
|
+ }
|
|
|
+ else if (setting.Equals("exam"))
|
|
|
+ {
|
|
|
+ setName.Add("评测活动");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ switch (study.type)
|
|
|
+ {
|
|
|
+ case 1:
|
|
|
+ tname = "信息化教学案例展示与分享";
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ tname = "专家专题培训";
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ tname = "同课同构";
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ tname = "同课异构";
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ tname = "校本2.0培训";
|
|
|
+ break;
|
|
|
+ case 6:
|
|
|
+ tname = "自定义活动";
|
|
|
+ break;
|
|
|
+ };
|
|
|
+ stringBuilder.Append($@"<tr>
|
|
|
+ <td> {study.topic} </td>
|
|
|
+ <td> {tname} </td >
|
|
|
+ <td> {study.hour} </td >
|
|
|
+ <td> 1 </td >
|
|
|
+ <td> {start} 到 {end} </td>
|
|
|
+ <td>{study.desc}</td>
|
|
|
+ <td> {string.Join("、", setName.Select(x => $"{x}\n"))} </td>
|
|
|
+ <td> 已完成 </td >
|
|
|
+ </tr> ");
|
|
|
+ }
|
|
|
+ string blob = await StudyService.GenPdf(cname, sname, gname, stringBuilder.ToString(), _converter);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /*var query = $"select c.id,c.name,c.type,c.hour,c.startTime,c.endTime,c.presenter,c.topic from c where (c.status<>404 or IS_DEFINED(c.status) = false and array_contains(c.teacIds, '{id}') )";
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<Study>(queryText: query, requestOptions: new QueryRequestOptions() {PartitionKey = new PartitionKey($"Study-{code}") }))
|
|
|
+ {
|
|
|
+ studies.Add(item);
|
|
|
+
|
|
|
+ }*/
|
|
|
+ //(List<StuActivity> datas, string continuationToken) = await ActivityStudentService.FindActivity(element, null, null, _azureCosmos, _azureRedis);
|
|
|
+
|
|
|
+ // string blob = await StudyService.GenPdf(cname,sname,gname,"", _converter);
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (CosmosException ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,GenPdfFunc()\n{ex.Message}\n{ex.StackTrace}\n\n{msg}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,GenPdfFunc()\n{ex.Message}\n{ex.StackTrace}\n\n{msg}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ }
|
|
|
+ }
|
|
|
//更新學校產品一覽表
|
|
|
//處理內容:取得所有序號購買紀錄,服務週期、硬體購買紀錄後,更新ProductSum
|
|
|
[Function("Product")]
|
|
@@ -682,7 +854,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
////服務產品特別對應項
|
|
|
School school = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{schoolId}", new PartitionKey("Base")); //學校基本資料取得
|
|
@@ -874,7 +1046,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
|
|
|
}
|
|
|
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
-
|
|
|
+
|
|
|
if ($"{scope}".Equals("school") && !string.IsNullOrEmpty($"{school}"))
|
|
|
{
|
|
|
blobname = $"{school}";
|
|
@@ -1006,18 +1178,18 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
|
|
|
tmdid = lessonRecord.tmdid,
|
|
|
code = "LessonStudentRecord",
|
|
|
pk = "LessonStudentRecord",
|
|
|
- courseId =lessonRecord.courseId,
|
|
|
- groupIds= lessonRecord.groupIds,
|
|
|
+ courseId = lessonRecord.courseId,
|
|
|
+ groupIds = lessonRecord.groupIds,
|
|
|
periodId = lessonRecord.periodId,
|
|
|
subjectId = lessonRecord.subjectId,
|
|
|
};
|
|
|
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS,Constant.Student).UpsertItemAsync<LessonStudentRecord>(lessonStudentRecord, new PartitionKey("LessonStudentRecord"));
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).UpsertItemAsync<LessonStudentRecord>(lessonStudentRecord, new PartitionKey("LessonStudentRecord"));
|
|
|
}
|
|
|
//有上传 base.josn.
|
|
|
- lessonRecord.upload =1;
|
|
|
+ lessonRecord.upload = 1;
|
|
|
// await _dingDing.SendBotMsg($"{_option.Location},课堂id:{_lessonId} 更新完成", GroupNames.醍摩豆服務運維群組);
|
|
|
|
|
|
- LessonService.DoAutoDeleteSchoolLessonRecord(lessonRecord, scope, client, school, tmdid, teacher, _notificationService, _serviceBus, _azureStorage, _configuration);
|
|
|
+ LessonService.DoAutoDeleteSchoolLessonRecord(lessonRecord, scope, client, school, tmdid, teacher, _notificationService, _serviceBus, _azureStorage, _configuration);
|
|
|
long? size = await _azureStorage.GetBlobContainerClient(blobname).GetBlobsSize($"records/{_lessonId}");
|
|
|
Bloblog bloblog = new Bloblog
|
|
|
{
|
|
@@ -1124,7 +1296,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
|
|
|
case "create":
|
|
|
oldlessonRecord = null;
|
|
|
//处理课堂选用的课程信息
|
|
|
-
|
|
|
+
|
|
|
lessonRecord.show = teacher.lessonShow;
|
|
|
lessonRecord.upload = 0;
|
|
|
if (!string.IsNullOrEmpty(lessonRecord.courseId))
|
|
@@ -1279,7 +1451,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
|
|
|
//var day3= now.AddDays(Constant.private_lesson_expire - 3).ToUnixTimeMilliseconds();
|
|
|
//result.Add(3, day3);
|
|
|
//剩余1天的通知
|
|
|
- var day1 = now.AddDays(Constant.private_lesson_expire - (Constant.private_lesson_expire-1)).ToUnixTimeMilliseconds();
|
|
|
+ var day1 = now.AddDays(Constant.private_lesson_expire - (Constant.private_lesson_expire - 1)).ToUnixTimeMilliseconds();
|
|
|
result.Add(1, new ExpireTag { expire = day1, tag = "notification" });
|
|
|
//到期通知
|
|
|
|
|
@@ -1291,7 +1463,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
|
|
|
addSecond = Constant.private_lesson_expire * 86400 + (24 - now.Hour) * 3600;
|
|
|
//再加 00到05小时内的 随机秒数
|
|
|
Random rand = new Random();
|
|
|
- int randInt= rand.Next(0 , 18000);
|
|
|
+ int randInt = rand.Next(0, 18000);
|
|
|
addSecond += randInt;
|
|
|
}
|
|
|
else
|
|
@@ -1307,7 +1479,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
|
|
|
{
|
|
|
hubName = "hita",
|
|
|
type = "msg",
|
|
|
- from = $"ies5:{ Environment.GetEnvironmentVariable("Option:Location")}:private",
|
|
|
+ from = $"ies5:{Environment.GetEnvironmentVariable("Option:Location")}:private",
|
|
|
to = new List<string> { tmdid },
|
|
|
label = $"{biz}_lessonRecord",
|
|
|
body = new
|
|
@@ -1318,7 +1490,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
|
|
|
tmdname = teacher.name,
|
|
|
sid = lessonRecord.id,
|
|
|
sname = lessonRecord.name,
|
|
|
- scope=scope,
|
|
|
+ scope = scope,
|
|
|
stime = lessonRecord.startTime,
|
|
|
expire = lessonRecord.expire,
|
|
|
status = 1,
|
|
@@ -1426,7 +1598,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
|
|
|
jsonMsg.TryGetProperty("tag", out JsonElement _tag);
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
//处理到期删除
|
|
|
- if (_tag.ValueKind.Equals(JsonValueKind.String) && $"{_tag}".Equals("delete") )
|
|
|
+ if (_tag.ValueKind.Equals(JsonValueKind.String) && $"{_tag}".Equals("delete"))
|
|
|
{
|
|
|
string lessonId = $"{id}";
|
|
|
string tbname;
|
|
@@ -1559,7 +1731,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
|
|
|
else
|
|
|
{
|
|
|
|
|
|
- await _dingDing.SendBotMsg($"OS,{ Environment.GetEnvironmentVariable("Option:Location")},CourseServiceBus -CosmosDB异常\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ await _dingDing.SendBotMsg($"OS,{Environment.GetEnvironmentVariable("Option:Location")},CourseServiceBus -CosmosDB异常\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1596,7 +1768,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
|
|
|
else
|
|
|
{
|
|
|
|
|
|
- await _dingDing.SendBotMsg($"OS,{ Environment.GetEnvironmentVariable("Option:Location")},CourseServiceBus -CosmosDB异常\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ await _dingDing.SendBotMsg($"OS,{Environment.GetEnvironmentVariable("Option:Location")},CourseServiceBus -CosmosDB异常\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1640,7 +1812,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
|
|
|
else
|
|
|
{
|
|
|
|
|
|
- await _dingDing.SendBotMsg($"OS,{ Environment.GetEnvironmentVariable("Option:Location")},CourseServiceBus -CosmosDB异常\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ await _dingDing.SendBotMsg($"OS,{Environment.GetEnvironmentVariable("Option:Location")},CourseServiceBus -CosmosDB异常\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1678,7 +1850,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
|
|
|
else
|
|
|
{
|
|
|
|
|
|
- await _dingDing.SendBotMsg($"OS,{ Environment.GetEnvironmentVariable("Option:Location")},CourseServiceBus -CosmosDB异常\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ await _dingDing.SendBotMsg($"OS,{Environment.GetEnvironmentVariable("Option:Location")},CourseServiceBus -CosmosDB异常\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1740,7 +1912,7 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
|
|
|
}
|
|
|
catch (CosmosException ex)
|
|
|
{
|
|
|
- await _dingDing.SendBotMsg($"OS,{ Environment.GetEnvironmentVariable("Option:Location")},CourseServiceBus -CosmosDB异常\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ await _dingDing.SendBotMsg($"OS,{Environment.GetEnvironmentVariable("Option:Location")},CourseServiceBus -CosmosDB异常\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1800,14 +1972,14 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
|
|
|
}
|
|
|
catch (CosmosException ex)
|
|
|
{
|
|
|
- await _dingDing.SendBotMsg($"OS,{ Environment.GetEnvironmentVariable("Option:Location")},CourseServiceBus -CosmosDB异常\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ await _dingDing.SendBotMsg($"OS,{Environment.GetEnvironmentVariable("Option:Location")},CourseServiceBus -CosmosDB异常\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- await _dingDing.SendBotMsg($"OS,{ Environment.GetEnvironmentVariable("Option:Location")},CourseServiceBus -Course\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ await _dingDing.SendBotMsg($"OS,{Environment.GetEnvironmentVariable("Option:Location")},CourseServiceBus -Course\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
}
|
|
|
}
|
|
|
}
|