From 0fb97336ffe3bcad440670288c3961424b648331 Mon Sep 17 00:00:00 2001 From: qian Date: Thu, 6 Jun 2024 14:35:19 +0800 Subject: [PATCH] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Models/ScpEntity/TS_Email.cs | 2 ++ UniApiGroup/Controller/MailController.cs | 35 ++++++++++++++---------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Models/ScpEntity/TS_Email.cs b/Models/ScpEntity/TS_Email.cs index a0b746c..c8fc400 100644 --- a/Models/ScpEntity/TS_Email.cs +++ b/Models/ScpEntity/TS_Email.cs @@ -20,6 +20,8 @@ namespace CK.SCP.Models.ScpEntity public int EmailSendState { get; set; } [DisplayName("失败原因")] public string EmailSendFailReason { get; set; } + [DisplayName("发送时间")] + public string UpdateTime { get; set; } } } diff --git a/UniApiGroup/Controller/MailController.cs b/UniApiGroup/Controller/MailController.cs index 31c8897..e20dfba 100644 --- a/UniApiGroup/Controller/MailController.cs +++ b/UniApiGroup/Controller/MailController.cs @@ -182,37 +182,44 @@ namespace CK.SCP.UniApi.Controller /// public static void SendOrderMail() { - AppBoxContext DB = EntitiesFactory.CreateAppBoxInstance(); ScpEntities SDB = EntitiesFactory.CreateScpInstance(); var emailList = SDB.TS_Email.Where(q => q.EmailSendState == 0).ToList(); try { foreach (var item in emailList) { - MailManager.SendMailOrders(item.EmailAddress, item.EmailString, "鏉愭枡璁㈠崟鎻愰啋"); - Console.WriteLine($"鍙戦侀偖浠讹細渚涘簲鍟嗕负{ item.EmailToUser}"); + try + { + MailManager.SendMailOrders(item.EmailAddress, item.EmailString, "鏉愭枡璁㈠崟鎻愰啋"); + Console.WriteLine($"鍙戦侀偖浠讹細渚涘簲鍟嗕负{ item.EmailToUser}"); + item.EmailSendState = 1; + item.UpdateTime = DateTime.Now.ToString(); + } + catch (Exception ex) + { + item.EmailSendState = 2; + item.EmailSendFailReason = ex.Message; + continue; + } + } - emailList.ForEach(q => - { - q.EmailSendState = 1; - }); SDB.TS_Email.AddOrUpdate(q => q.UID, emailList.ToArray()); SDB.SaveChanges(); } catch(Exception ex) { - emailList.ForEach(q => - { - q.EmailSendState = 2; - q.EmailSendFailReason = ex.Message; - }); + //emailList.ForEach(q => + //{ + // q.EmailSendState = 2; + // q.EmailSendFailReason = ex.Message; + //}); Console.WriteLine(ex.Message); if (ex.InnerException != null) { Console.WriteLine(ex.InnerException.Message); } - SDB.TS_Email.AddOrUpdate(q => q.UID, emailList.ToArray()); - SDB.SaveChanges(); + //SDB.TS_Email.AddOrUpdate(q => q.UID, emailList.ToArray()); + //SDB.SaveChanges(); } }