|
@@ -1,16 +1,23 @@
|
|
|
+using HTEXLib.COMM.Helpers;
|
|
|
+using Microsoft.AspNetCore.Hosting;
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
+using Microsoft.Extensions.Hosting;
|
|
|
using Microsoft.Extensions.Options;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Dynamic;
|
|
|
+using System.IO;
|
|
|
+using System.Linq;
|
|
|
using System.Net;
|
|
|
using System.Net.Http;
|
|
|
using System.Net.Http.Json;
|
|
|
using System.Text;
|
|
|
using System.Text.Json;
|
|
|
using System.Threading.Tasks;
|
|
|
+using TEAMModelOS.SDK.DI;
|
|
|
using TEAMModelOS.SDK.Extension;
|
|
|
-
|
|
|
+using TEAMModelOS.SDK.Models;
|
|
|
|
|
|
namespace TEAMModelOS.SDK
|
|
|
{
|
|
@@ -38,14 +45,17 @@ namespace TEAMModelOS.SDK
|
|
|
}
|
|
|
public class CoreAPIHttpService
|
|
|
{
|
|
|
-
|
|
|
+ private readonly IWebHostEnvironment _environment;
|
|
|
public bool check=true;
|
|
|
+ private SnowflakeId _snowflakeId;
|
|
|
private readonly HttpClient _httpClient;
|
|
|
public readonly IOptionsMonitor<CoreAPIHttpServiceOptions> options;
|
|
|
- public CoreAPIHttpService(HttpClient httpClient, IOptionsMonitor<CoreAPIHttpServiceOptions> optionsMonitor)
|
|
|
+ public CoreAPIHttpService(HttpClient httpClient, IOptionsMonitor<CoreAPIHttpServiceOptions> optionsMonitor, IWebHostEnvironment environment,SnowflakeId snowflakeId)
|
|
|
{
|
|
|
_httpClient = httpClient;
|
|
|
options = optionsMonitor;
|
|
|
+ _environment = environment;
|
|
|
+ _snowflakeId= snowflakeId;
|
|
|
}
|
|
|
/*
|
|
|
hubName string Optional 指定要傳送到哪個訊息中樞,若沒給則不傳送端外通知,只會發送端內通知。(目前只有"hita"及"hita5"能使用)
|
|
@@ -56,17 +66,89 @@ namespace TEAMModelOS.SDK
|
|
|
eventId string Optional 事件ID
|
|
|
eventName string Optional 事件名稱
|
|
|
data string Optional 額外資料
|
|
|
+
|
|
|
+
|
|
|
+ 'request_school': vm.$t('notice.type1'), // 管理员收到他人申请加入的通知
|
|
|
+ 'invite_school': vm.$t('notice.type2'), // 你收到学校邀请你的通知
|
|
|
+ 'remove_school': vm.$t('notice.type3'), // 学校将你移除的通知
|
|
|
+ 'request-join_school': vm.$t('notice.type1'), // 学校同意你的加入请求
|
|
|
+ 'invite-join_school': vm.$t('notice.type2'), // 某人已同意你对他的邀请
|
|
|
+ 'coedit_syllabus': vm.$t('notice.type4'), // 邀请课纲共编的通知
|
|
|
+ 'share_syllabus': vm.$t('notice.type4'), // 个人课纲分享的通知
|
|
|
+ 'transfer-admin_school': vm.$t('notice.type5'), // 管理员转移的通知
|
|
|
+ 'scoring-arb_school': vm.$t('notice.type6'), // 仲裁卷阅卷任务分配通知
|
|
|
+ 'scoring-err_school': vm.$t('notice.type6'), // 异常卷阅卷任务分配通知
|
|
|
+ 'scoring-mark_school': vm.$t('notice.type6'), // 普通阅卷任务分配通知
|
|
|
+ 'scan-join_groupList': vm.$t('notice.type7'), // 扫码加入名单通知
|
|
|
+ 'scan-join_school': vm.$t('notice.type7'), // 扫码加入学校通知
|
|
|
+ 'submitanswer_homework': vm.$t('notice.type8'), // 作业提交通知
|
|
|
+ 'expire_lessonRecord': vm.$t('notice.type9'), // 课例过期通知
|
|
|
*/
|
|
|
/// <summary>
|
|
|
+ ///
|
|
|
/// 發送端內外通知
|
|
|
+ ///
|
|
|
+ /// id: 教师id,name 教师名称,code 语系
|
|
|
/// </summary>
|
|
|
- /// <param name="clientID"></param>
|
|
|
- /// <param name="clientSecret"></param>
|
|
|
+ /// <param name="toTeachers"></param>
|
|
|
+ /// <param name="notifyCode"></param>
|
|
|
+ /// <param name="replaceData"></param>
|
|
|
/// <param name="location"></param>
|
|
|
- /// <param name="url"></param>
|
|
|
- /// <param name="data"></param>
|
|
|
+ /// <param name="_configuration"></param>
|
|
|
+ /// <param name="_dingDing"></param>
|
|
|
/// <returns></returns>
|
|
|
- public async Task<(HttpStatusCode code, string content)> PushNotify(Dictionary<string, object> data, string location, IConfiguration _configuration, DI.DingDing _dingDing) {
|
|
|
+ public (HttpStatusCode code, string content) PushNotify(List<IdNameCode> toTeachers , string notifyCode,Dictionary<string, object> replaceData, string location, IConfiguration _configuration, DI.DingDing _dingDing) {
|
|
|
+ /*
|
|
|
+ {
|
|
|
+ "hubName":"hita5",
|
|
|
+ "sender":"ies5",
|
|
|
+ "tags":["1595321354_ies5"]
|
|
|
+ "title":"",
|
|
|
+ "body":"",
|
|
|
+ "eventId":"",
|
|
|
+ "eventName":"",
|
|
|
+ "data":""
|
|
|
+ }
|
|
|
+ */
|
|
|
+ string lang = location.Contains("China") ? "zh-cn" : "en-us";
|
|
|
+ toTeachers.FindAll(x => string.IsNullOrWhiteSpace(x.code)||(!x.code.Equals("zh-cn")&& !x.code.Equals("zh-tw")&& !x.code.Equals("en-us"))).ForEach(x => { x.code = lang; });
|
|
|
+ var groups = toTeachers.GroupBy(x => x.code).Select(x => new { x.Key, list = x.ToList() });
|
|
|
+
|
|
|
+ foreach(var group in groups)
|
|
|
+ {
|
|
|
+ string path = $"{_environment.ContentRootPath}/JsonFile/Core/Lang/{group.Key}.json";
|
|
|
+ var sampleJson = File.ReadAllBytes(path).AsSpan();
|
|
|
+ Utf8JsonReader reader = new Utf8JsonReader(sampleJson);
|
|
|
+ if (JsonDocument.TryParseValue(ref reader, out JsonDocument jsonDoc) && jsonDoc.RootElement.TryGetProperty(notifyCode, out JsonElement json )) {
|
|
|
+ List<string> msgs = json.ToObject<List<string>>();
|
|
|
+ if (msgs.IsNotEmpty()) {
|
|
|
+ var tags= group.list.Select(x => $"{x.id}_ies5");
|
|
|
+ dynamic notifyData = new ExpandoObject();
|
|
|
+ if (msgs.Count == 1)
|
|
|
+ {
|
|
|
+ notifyData.hubName = "hita5";
|
|
|
+ notifyData.sender = "ies5";
|
|
|
+ notifyData.tags = tags;
|
|
|
+ notifyData.title = msgs[0];
|
|
|
+ notifyData.body = msgs[0];
|
|
|
+ notifyData.eventId = $"{notifyCode}-{_snowflakeId.NextId()}";
|
|
|
+ notifyData.eventName = $"{msgs[0]}";
|
|
|
+ notifyData.data = replaceData;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ notifyData.hubName = "hita5";
|
|
|
+ notifyData.sender = "ies5";
|
|
|
+ notifyData.tags = tags;
|
|
|
+ notifyData.title = msgs[0];
|
|
|
+ notifyData.body =replaceData.Keys.Select(x => msgs[1].Replace("{"+x+"}", $"{replaceData[x]}"));
|
|
|
+ notifyData.eventId = $"{notifyCode}-{_snowflakeId.NextId()}";
|
|
|
+ notifyData.eventName = $"{msgs[0]}";
|
|
|
+ notifyData.data = replaceData;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
return (HttpStatusCode.BadRequest, null);
|
|
|
}
|
|
|
|