From 0005e17b3b832b5def1d91f532255e85273eb0bc Mon Sep 17 00:00:00 2001 From: lyndonliu Date: Mon, 1 Apr 2024 17:51:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BC=82=E5=B8=B8=E9=92=89=E9=92=89?= =?UTF-8?q?=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Exams/ExamManager.cs | 1 + .../Services/ExamAppService.cs | 6 ++++++ .../Extensions/NotifyExt.cs | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 Dolphin.ExamPictureCut.Core/Extensions/NotifyExt.cs diff --git a/Dolphin.ExamPictureCut.Application/Exams/ExamManager.cs b/Dolphin.ExamPictureCut.Application/Exams/ExamManager.cs index 7464b60..abb8e72 100644 --- a/Dolphin.ExamPictureCut.Application/Exams/ExamManager.cs +++ b/Dolphin.ExamPictureCut.Application/Exams/ExamManager.cs @@ -445,6 +445,7 @@ public class ExamManager : DomainService, IExamManager catch (Exception ex) { Logger.LogError("{ExamSubjectId} {penSerial} 收集失败! {error}", eto.ExamSubjectId, penSerial, ex); + await NotifyExt.DingTalk($"{eto.ExamSubjectId} {penSerial} 收集失败! 异常:{ex.Message}"); } finally { diff --git a/Dolphin.ExamPictureCut.Application/Services/ExamAppService.cs b/Dolphin.ExamPictureCut.Application/Services/ExamAppService.cs index 8756216..7650ee7 100644 --- a/Dolphin.ExamPictureCut.Application/Services/ExamAppService.cs +++ b/Dolphin.ExamPictureCut.Application/Services/ExamAppService.cs @@ -1,4 +1,5 @@ using Dolphin.ExamPictureCut.Exams; +using Dolphin.ExamPictureCut.Extensions; namespace Dolphin.ExamPictureCut.Services; @@ -14,4 +15,9 @@ public class ExamAppService : DolphinAppService { await _examManager.ExamStudentGather(new() { SchoolId = 3, StudentExamNum = "BP2-3G3-07K-C1", BookId = 529493484986437, ExamSubjectSchoolId = 530151338438726, ExamSubjectId = 530151329325125, LastCollectTime = DateTime.Now }); } + + public async Task NotifyTest() + { + await NotifyExt.DingTalk($"{530151329325125} {"BP2-3G3-07K-C1"} 收集失败! 异常: {"通知测试"}"); + } } diff --git a/Dolphin.ExamPictureCut.Core/Extensions/NotifyExt.cs b/Dolphin.ExamPictureCut.Core/Extensions/NotifyExt.cs new file mode 100644 index 0000000..c95635c --- /dev/null +++ b/Dolphin.ExamPictureCut.Core/Extensions/NotifyExt.cs @@ -0,0 +1,19 @@ +using Flurl.Http; + +namespace Dolphin.ExamPictureCut.Extensions; + +public class NotifyExt +{ + public static async Task DingTalk(string text) + { + await "https://oapi.dingtalk.com/robot/send?access_token=6ddafcada8f44f4bad4a7314c4d9bd19a895ded0a1ba1afdaff5dd01a5af6781".PostJsonAsync(new + { + msgtype = "markdown", + markdown = new + { + title = "异常通知", + text = $"dotpan,{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}异常\n > 来源:Dplphin.ExamPictureCut\n > 详情:" + text, + } + }).ReceiveString(); + } +}