|
@@ -788,14 +788,14 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
|
|
|
from = $"BI:{_option.Location}:private",
|
|
|
to = bIBatchCopyFile.tmdIds,
|
|
|
label = $"{bIBatchCopyFile.codeKey}_finish",
|
|
|
- body = new { location = _option.Location, biz = $"{bIBatchCopyFile.codeKey}", tmdid = $"{bIBatchCopyFile.tmdid}", tmdname = $"{bIBatchCopyFile.tmdName}", status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
|
|
|
+ body = new { location = $"{Environment.GetEnvironmentVariable("Option:Location")}", biz = $"{bIBatchCopyFile.codeKey}", tmdid = $"{bIBatchCopyFile.tmdid}", tmdname = $"{bIBatchCopyFile.tmdName}", status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
|
|
|
expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
|
|
|
};
|
|
|
|
|
|
var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
|
|
|
var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
|
var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
|
|
|
- var location = _option.Location;
|
|
|
+ var location = $"{Environment.GetEnvironmentVariable("Option:Location")}";
|
|
|
await _notificationService.SendNotification(clientID, clientSecret, location, url, notification); //站内发送消息
|
|
|
}
|
|
|
}
|
|
@@ -1144,6 +1144,128 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
|
|
|
}
|
|
|
lessonRecord.grade= grades.ToList();
|
|
|
}
|
|
|
+ //个人课例保存规则
|
|
|
+ try {
|
|
|
+ if (scope.Equals("private"))
|
|
|
+ {
|
|
|
+ Teacher teacher = await client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<Teacher>(tmdid, new PartitionKey("Base"));
|
|
|
+ if (teacher.lessonLimit != -1)
|
|
|
+ {
|
|
|
+
|
|
|
+ HashSet<string> ids = new HashSet<string>();
|
|
|
+ //未定义的 以及过期时间小于等于0 的 课例
|
|
|
+ string private_count_sql = "select value(c.id) from c where ( c.expire<=0 or IS_DEFINED(c.expire) = false ) ";
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryIterator<string>(
|
|
|
+ queryText: private_count_sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey(code) }))
|
|
|
+ {
|
|
|
+
|
|
|
+ ids.Add(item);
|
|
|
+ }
|
|
|
+ //包含收藏的本人的个人课例
|
|
|
+ string favorite_count_sql = $"select value(c.id) from c where c.fromCode='LessonRecord-{tmdid}' and c.scope='private' ";
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryIterator<string>(
|
|
|
+ queryText: favorite_count_sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Favorite-{tmdid}") }))
|
|
|
+ {
|
|
|
+ ids.Add(item);
|
|
|
+ }
|
|
|
+ //教师个人预设的,可以通过设置的方式增加
|
|
|
+ int limit = teacher.lessonLimit;
|
|
|
+ if (teacher.lessonLimit == 0)
|
|
|
+ {
|
|
|
+ //未设置的的采用系统设置的默认值30
|
|
|
+ limit = Constant.private_lesson_limit;
|
|
|
+ }
|
|
|
+ if (ids.Count >= limit)
|
|
|
+ {
|
|
|
+ // 1-时间戳,7-时间戳
|
|
|
+ Dictionary<int, long> result = new Dictionary<int, long>();
|
|
|
+ //暂定7天
|
|
|
+ var now = DateTimeOffset.UtcNow;
|
|
|
+ //剩余3天的通知
|
|
|
+ //var day3= now.AddDays(Constant.private_lesson_expire - 3).ToUnixTimeMilliseconds();
|
|
|
+ //result.Add(3, day3);
|
|
|
+ //剩余1天的通知
|
|
|
+ var day1 = now.AddDays(Constant.private_lesson_expire -6).ToUnixTimeMilliseconds();
|
|
|
+ result.Add(1, day1);
|
|
|
+ //到期通知
|
|
|
+ lessonRecord.expire = now.AddDays(Constant.private_lesson_expire).ToUnixTimeMilliseconds();
|
|
|
+ result.Add(Constant.private_lesson_expire, lessonRecord.expire);
|
|
|
+ string biz = "expire";
|
|
|
+ Notification notification = new Notification
|
|
|
+ {
|
|
|
+ hubName = "hita",
|
|
|
+ type = "msg",
|
|
|
+ from = $"ies5:{ Environment.GetEnvironmentVariable("Option:Location")}:private",
|
|
|
+ to = new List<string> { tmdid },
|
|
|
+ label = $"{biz}_lessonRecord",
|
|
|
+ body = new {
|
|
|
+ location = $"{Environment.GetEnvironmentVariable("Option:Location")}",
|
|
|
+ biz = biz,
|
|
|
+ tmdid = teacher.id,
|
|
|
+ tmdname = teacher.name,
|
|
|
+ sid = lessonRecord.id,
|
|
|
+ sname = lessonRecord.name,
|
|
|
+ stime = lessonRecord.startTime,
|
|
|
+ expire = lessonRecord.expire,
|
|
|
+ status = 1,
|
|
|
+ day = Constant.private_lesson_expire,
|
|
|
+ time = now
|
|
|
+ }.ToJsonString(),
|
|
|
+ expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
|
|
|
+ };
|
|
|
+ var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
|
|
|
+ var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
|
+ var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
|
|
|
+ var location = $"{Environment.GetEnvironmentVariable("Option:Location")}";
|
|
|
+ await _notificationService.SendNotification(clientID, clientSecret, location, url, notification); //站内发送消息
|
|
|
+
|
|
|
+ var table = _azureStorage.GetCloudTableClient().GetTableReference("ChangeRecord");
|
|
|
+ List<ChangeRecord> records = await table.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", lessonRecord.id } });
|
|
|
+ if (records.Count <= 0)
|
|
|
+ {
|
|
|
+ foreach (var item in result)
|
|
|
+ {
|
|
|
+ string PartitionKey = string.Format("{0}{1}{2}", lessonRecord.code, "-", $"expire-{item.Key}");
|
|
|
+ //课堂的id ,
|
|
|
+ //课堂的通知时间类型progress, 默认就会发送一条,到期前一天发送一条,最后已到期发送一条。
|
|
|
+ var message = new ServiceBusMessage(new
|
|
|
+ {
|
|
|
+ id = lessonRecord.id,
|
|
|
+ progress = item.Key,
|
|
|
+ code = lessonRecord.code,
|
|
|
+ scope = lessonRecord.scope,
|
|
|
+ school = lessonRecord.school,
|
|
|
+ opt = "delete",
|
|
|
+ expire = lessonRecord.expire,
|
|
|
+ tmdid = tmdid,
|
|
|
+ tmdname = teacher.name,
|
|
|
+ name = lessonRecord.name,
|
|
|
+ startTime = lessonRecord.startTime
|
|
|
+ }.ToJsonString());
|
|
|
+ message.ApplicationProperties.Add("name", "LessonRecordExpire");
|
|
|
+ long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), message, DateTimeOffset.FromUnixTimeMilliseconds(item.Value));
|
|
|
+ ChangeRecord changeRecord = new ChangeRecord
|
|
|
+ {
|
|
|
+ RowKey = lessonRecord.id,
|
|
|
+ PartitionKey = PartitionKey,
|
|
|
+ sequenceNumber = start,
|
|
|
+ msgId = message.MessageId
|
|
|
+ };
|
|
|
+ await table.Save<ChangeRecord>(changeRecord);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //=-1 则表示不限制上传数量
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-处理课堂记录的-CosmosDB异常{e.Message}\n{e.StackTrace}\n{lessonRecord.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
msgs.Add(update);
|
|
|
break;
|
|
|
default:
|
|
@@ -1168,7 +1290,93 @@ namespace TEAMModelOS.FunctionV4.ServiceBus
|
|
|
await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-更新课堂记录出错\n{ex.Message}\n{ex.StackTrace}\n{data}\n{code}\n{updates}\n", GroupNames.醍摩豆服務運維群組);
|
|
|
}
|
|
|
}
|
|
|
+ [Function("LessonRecordExpire")]
|
|
|
+ public async Task LessonRecordExpireFunc([ServiceBusTrigger("%Azure:ServiceBus:ActiveTask%", "lesson-record-expire", Connection = "Azure:ServiceBus:ConnectionString")] string msg)
|
|
|
+ {
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var jsonMsg = JsonDocument.Parse(msg).RootElement;
|
|
|
+ jsonMsg.TryGetProperty("id", out JsonElement id);
|
|
|
+ jsonMsg.TryGetProperty("progress", out JsonElement progress);
|
|
|
+ jsonMsg.TryGetProperty("code", out JsonElement _code);
|
|
|
+ jsonMsg.TryGetProperty("tmdid", out JsonElement tmdid);
|
|
|
+ jsonMsg.TryGetProperty("tmdname", out JsonElement tmdname);
|
|
|
+ jsonMsg.TryGetProperty("name", out JsonElement name);
|
|
|
+ jsonMsg.TryGetProperty("startTime", out JsonElement startTime);
|
|
|
+ jsonMsg.TryGetProperty("expire", out JsonElement expire);
|
|
|
+ jsonMsg.TryGetProperty("scope", out JsonElement scope);
|
|
|
+ jsonMsg.TryGetProperty("school", out JsonElement _school);
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ //处理到期删除
|
|
|
+ if ($"{progress}".Equals($"{Constant.private_lesson_expire}")) {
|
|
|
+ string lessonId = $"{id}";
|
|
|
+ string tbname;
|
|
|
+ string school=$"{_school}";
|
|
|
+ string code = "";
|
|
|
+ if ($"{scope}".Equals("school") && !string.IsNullOrEmpty($"{school}"))
|
|
|
+ {
|
|
|
+ code = $"LessonRecord-{school}";
|
|
|
+ tbname = "School";
|
|
|
+ }
|
|
|
+ else if ($"{scope}".Equals("private"))
|
|
|
+ {
|
|
|
+ code = $"LessonRecord-{tmdid}";
|
|
|
+ tbname = "Teacher";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Azure.Response response = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemStreamAsync(lessonId, new PartitionKey(code));
|
|
|
+ if (response.Status == 200)
|
|
|
+ {
|
|
|
+ LessonRecord lessonRecord;
|
|
|
+ var doc = JsonDocument.Parse(response.ContentStream);
|
|
|
+ lessonRecord = doc.RootElement.ToObject<LessonRecord>();
|
|
|
+ lessonRecord.status = 404;
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, tbname).ReplaceItemAsync(lessonRecord, lessonRecord.id, new PartitionKey(lessonRecord.code));
|
|
|
+ var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
|
|
|
+ var messageChange = new ServiceBusMessage(new { delete_id =lessonId, tmdid =tmdid,scope=scope,opt="delete",school=school}.ToJsonString());
|
|
|
+ messageChange.ApplicationProperties.Add("name", "LessonRecordEvent");
|
|
|
+ await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageChange);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ string biz = "expire";
|
|
|
+ Notification notification = new Notification
|
|
|
+ {
|
|
|
+ hubName = "hita",
|
|
|
+ type = "msg",
|
|
|
+ from = $"ies5:{_option.Location}:private",
|
|
|
+ to = new List<string> { $"{tmdid}" },
|
|
|
+ label = $"{biz}_lessonRecord",
|
|
|
+ body = new {
|
|
|
+ location = $"{Environment.GetEnvironmentVariable("Option:Location")}",
|
|
|
+ biz = biz,
|
|
|
+ tmdid = $"{tmdid}",
|
|
|
+ tmdname = tmdname,
|
|
|
+ sid =$"{id}",
|
|
|
+ sname = $"{name}",
|
|
|
+ stime = long.Parse($"{startTime}"),
|
|
|
+ expire = long.Parse($"{expire}"),
|
|
|
+ status = 1,
|
|
|
+ day = Constant.private_lesson_expire,
|
|
|
+ time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
|
|
|
+ }.ToJsonString(),
|
|
|
+ expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
|
|
|
+ };
|
|
|
+ var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
|
|
|
+ var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
|
+ var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
|
|
|
+ var location =$"{Environment.GetEnvironmentVariable("Option:Location")}";
|
|
|
+ await _notificationService.SendNotification(clientID, clientSecret, location, url, notification); //站内发送消息
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Study()\n{ex.Message}\n{ex.StackTrace}\n{msg}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 完善课程变更
|