HiITEdenX 2 years ago
parent
commit
ead32c0a7b

+ 90 - 8
TEAMModelOS.SDK/DI/CoreAPI/CoreAPIHttpService.cs

@@ -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);
         }
 

+ 2 - 0
TEAMModelOS.SDK/Models/Cosmos/Teacher/Teacher.cs

@@ -25,6 +25,8 @@ namespace TEAMModelOS.SDK.Models
         /// </summary>
         public List<LoginInfo> loginInfos { get; set; } = new List<LoginInfo>();
 
+        public string lang { get; set; }
+
         public class LoginInfo
         {
             /// <summary>

+ 5 - 1
TEAMModelOS.SDK/Models/Service/Common/TeacherService.cs

@@ -29,7 +29,8 @@ namespace TEAMModelOS.Services
 {
     public static class TeacherService
     {
-        public static async Task<TeacherInfo> TeacherInfo(AzureCosmosFactory _azureCosmos, Teacher teacher, string name, string picture, string id, AzureStorageFactory _azureStorage, Option _option,AzureRedisFactory _azureRedis,string ip, HttpTrigger _httpTrigger)
+        public static async Task<TeacherInfo> TeacherInfo(AzureCosmosFactory _azureCosmos, Teacher teacher, string name, string picture, string id,
+            AzureStorageFactory _azureStorage, Option _option,AzureRedisFactory _azureRedis,string ip, HttpTrigger _httpTrigger,string lang )
         {
             List<object> schools = new List<object>();
             List<AreaDto> areas = new List<AreaDto>();
@@ -45,6 +46,9 @@ namespace TEAMModelOS.Services
                 if (teacher == null)
                 {
                     teacher = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>(id, new PartitionKey("Base"));
+                    if (!string.IsNullOrWhiteSpace(lang) &&  string.IsNullOrWhiteSpace(teacher.lang)) {
+                        teacher.lang = lang;
+                    }
                     teacher.name = $"{name}";
                     teacher.picture = $"{picture}";
                 }

+ 11 - 1
TEAMModelOS/Controllers/Both/ShareController.cs

@@ -244,7 +244,17 @@ namespace TEAMModelOS.Controllers
                                         from = $"ies5:{_option.Location}:private",
                                         to = new List<string>() { x.code.Replace("Share-", "").Replace($"{x.type}-", "") },
                                         label = $"{x.type}_syllabus",
-                                        body = new { location = _option.Location, biz = x.type, tmdid = x.issuer, tmdname = x.issuerName, sid = x.id, sname = x.syllabusName, vid = x.volumeId, vname = x.volumeName, status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
+                                        body = new { location = _option.Location,
+                                            biz = x.type,
+                                            tmdid = x.issuer,
+                                            tmdname = x.issuerName,
+                                            sid = x.id,
+                                            sname = x.syllabusName,
+                                            vid = x.volumeId,
+                                            vname = x.volumeName,
+                                            status = 1,
+                                            time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
+                                        }.ToJsonString(),
                                         expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
                                     };
                                     var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");

+ 21 - 2
TEAMModelOS/Controllers/Teacher/InitController.cs

@@ -125,7 +125,22 @@ namespace TEAMModelOS.Controllers
             {
                
                 switch (true)
-                {
+                { 
+                    //修改常用语系
+                    case bool when $"{_opt}".Equals("UpdateLang", StringComparison.OrdinalIgnoreCase) && (request.TryGetProperty("lang", out JsonElement lang)):
+                        {
+                            Teacher teacher = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>(userid, new PartitionKey("Base"));
+                            if (!string.IsNullOrEmpty($"{lang}"))
+                            {
+                                teacher.lang = $"{lang}";
+                                await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, userid, new PartitionKey("Base"));
+                                return Ok(new { teacher, status = 1 });
+                            }
+                            else
+                            {
+                                return BadRequest(new { status = -1, msg = "语系参数为空!" });
+                            }
+                        }
                     //修改默认学校
                     case bool when $"{_opt}".Equals("UpdateDefaultSchool", StringComparison.OrdinalIgnoreCase) && (request.TryGetProperty("defaultSchool", out JsonElement _defaultSchool)):
                         {
@@ -350,6 +365,10 @@ namespace TEAMModelOS.Controllers
         [HttpPost("get-teacher-info")]
         public async Task<IActionResult> GetTeacherInfo(JsonElement request)
         {
+            string lang = "";
+            if (HttpContext.Request.Headers.TryGetValue("lang", out var _lang)) {
+                lang = $"{_lang}";
+            }
             string OAuthShow_domain = HttpContext?.Request?.Host.Host;
             if (OAuthShow_domain.Equals("teammodelos.chinacloudsites.cn"))
             {
@@ -373,7 +392,7 @@ namespace TEAMModelOS.Controllers
             try
             {
                 Teacher teacher = null;
-                TeacherInfo teacherInfo = await TeacherService.TeacherInfo(_azureCosmos, teacher, $"{name}", $"{picture}", id, _azureStorage, _option, _azureRedis, ip, _httpTrigger);
+                TeacherInfo teacherInfo = await TeacherService.TeacherInfo(_azureCosmos, teacher, $"{name}", $"{picture}", id, _azureStorage, _option, _azureRedis, ip, _httpTrigger, $"{_lang}");
                 teacherInfo.areas.ForEach(x => { if (x.setting != null) { x.setting.accessConfig = x.setting.accessConfig; } });
                 LoginService.LoginLog(HttpContext, _option, _logger, _dingDing, ip, region, id, $"{name}", 200);
                 int lessonLimit = teacherInfo.teacher.lessonLimit;

+ 19 - 0
TEAMModelOS/JsonFile/Core/Lang/en-us.json

@@ -0,0 +1,19 @@
+{
+  //start 通知类语言包
+  "request_school": [ "申请加入学校通知", "" ], // 管理员收到他人申请加入的通知
+  "invite_school": [ "邀请加入学校通知", "" ], // 你收到学校邀请你的通知
+  "remove_school": [ "从学校移除通知", "" ], // 学校将你移除的通知
+  "request-join_school": [ "同意申请加入学校通知", "" ], // 学校同意你的加入请求
+  "invite-join_school": [ "同意邀请加入学校通知", "" ], // 某人已同意你对他的邀请
+  "coedit_syllabus": [ "邀请共编课纲通知", "" ], // 邀请课纲共编的通知
+  "share_syllabus": [ "课纲分享接收通知", "" ], // 个人课纲分享的通知
+  "transfer-admin_school": [ "管理员移交通知", "" ], // 管理员转移的通知
+  "scoring-arb_school": [ "仲裁卷阅卷任务通知", "" ], //仲裁卷阅卷任务分配通知
+  "scoring-err_school": [ "异常卷阅卷任务通知", "" ], //异常卷阅卷任务分配通知
+  "scoring-mark_school": [ "普通阅卷任务通知", "" ], //普通阅卷任务分配通知
+  "scan-join_groupList": [ "扫码加入名单通知", "" ], //扫码加入名单通知
+  "scan-join_school": [ "扫码加入学校通知", "" ], // 扫码加入学校通知
+  "submitanswer_homework": [ "作业提交通知", "" ], //作业提交通知
+  "expire_lessonRecord": [ "课例到期通知", "" ] //课例过期通知
+  //end  通知类语言包
+}

+ 20 - 0
TEAMModelOS/JsonFile/Core/Lang/zh-cn.json

@@ -0,0 +1,20 @@
+{
+  //start 通知类语言包
+  //通知类型编码 ["通知标题 title","通知内容 body"]
+  "request_school": [ "申请加入学校通知", "{tmdname}({tmdid})申请加入{schooName}。" ], // 管理员收到他人申请加入的通知
+  "invite_school": [ "邀请加入学校通知", "{schooName}邀请您加入学校。" ], // 你收到学校邀请你的通知
+  "remove_school": [ "从学校移除通知", "{schooName}将您从学校教师名单中移除。" ], // 学校将你移除的通知
+  "request-join_school": [ "同意申请加入学校通知", "{schooName}已同意您申请加入学校。" ], // 学校同意你的加入请求
+  "invite-join_school": [ "同意邀请加入学校通知", "{tmdname}已接受加入{schooName}的邀请。" ], // 某人已同意你对他的邀请
+  "coedit_syllabus": [ "邀请共编课纲通知", "{tmdname}邀请你参与共编校本课纲,册别名称:{volumeName},课纲节点名称:{syllabusName}。" ], // 邀请课纲共编的通知
+  "share_syllabus": [ "课纲分享接收通知", "{tmdname}向您分享了个人课纲,册别名称:{volumeName},课纲节点名称:{syllabusName}。" ], // 个人课纲分享的通知
+  "transfer-admin_school": [ "管理员移交通知", "{tmdname}将{schooName}的管理员移交给您。" ], // 管理员转移的通知
+  "scoring-arb_school": [ "仲裁卷阅卷任务通知", "{schoolname}的{tmdname}向您发送了仲裁卷阅卷任务。" ], //仲裁卷阅卷任务分配通知
+  "scoring-err_school": [ "异常卷阅卷任务通知", "{schoolname}的{tmdname}向您发送了异常卷阅卷任务。" ], //异常卷阅卷任务分配通知
+  "scoring-mark_school": [ "普通阅卷任务通知", "{schoolname}的{tmdname}向您发送了普通卷阅卷任务。" ], //普通阅卷任务分配通知
+  "scan-join_groupList": [ "扫码加入名单通知", "{tmdname}扫码加入名单,名单:{groupListName}" ], //扫码加入名单通知
+  "scan-join_school": [ "扫码加入学校通知", "{tmdname}扫码加入学校,学校名称:{schoolName}" ], // 扫码加入学校通知
+  "submitanswer_homework": [ "作业提交通知", "{tmdname}已提交作业,作业名称({homeworkName})" ], //作业提交通知
+  "expire-school_lessonRecord": [ "课例到期通知", "您在{schoolname}的课例将在{expireTime}到期,课例名称:{lessonRecordName}" ] //课例过期通知
+  //end  通知类语言包
+}

+ 19 - 0
TEAMModelOS/JsonFile/Core/Lang/zh-tw.json

@@ -0,0 +1,19 @@
+{
+  //start 通知类语言包
+  "request_school": [ "申请加入学校通知", "" ], // 管理员收到他人申请加入的通知
+  "invite_school": [ "邀请加入学校通知", "" ], // 你收到学校邀请你的通知
+  "remove_school": [ "从学校移除通知", "" ], // 学校将你移除的通知
+  "request-join_school": [ "同意申请加入学校通知", "" ], // 学校同意你的加入请求
+  "invite-join_school": [ "同意邀请加入学校通知", "" ], // 某人已同意你对他的邀请
+  "coedit_syllabus": [ "邀请共编课纲通知", "" ], // 邀请课纲共编的通知
+  "share_syllabus": [ "课纲分享接收通知", "" ], // 个人课纲分享的通知
+  "transfer-admin_school": [ "管理员移交通知", "" ], // 管理员转移的通知
+  "scoring-arb_school": [ "仲裁卷阅卷任务通知", "" ], //仲裁卷阅卷任务分配通知
+  "scoring-err_school": [ "异常卷阅卷任务通知", "" ], //异常卷阅卷任务分配通知
+  "scoring-mark_school": [ "普通阅卷任务通知", "" ], //普通阅卷任务分配通知
+  "scan-join_groupList": [ "扫码加入名单通知", "" ], //扫码加入名单通知
+  "scan-join_school": [ "扫码加入学校通知", "" ], // 扫码加入学校通知
+  "submitanswer_homework": [ "作业提交通知", "" ], //作业提交通知
+  "expire_lessonRecord": [ "课例到期通知", "" ] //课例过期通知
+  //end  通知类语言包
+}