Commit 5c339567 by Neo Turing

调整创建邮箱,在线查看报告,绩效考核调用接口的方式为后端封装方法进行调用。解决调用接口请求不稳定bug

parent 9f5ffba4
using Kivii.EmailPools.Entities;
using Kivii.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;
namespace Kivii.EmailPools
{
public static class Extension
{
public static List<EmailPool<G>> Accept<G>(this List<EmailPool> items, IDbConnection conn = null)
{
if (conn == null) conn = KiviiContext.GetOpenedDbConnection<EmailPool<G>>();
var rtns = new List<EmailPool<G>>();
foreach (var item in items)
{
try
{
try
{
var to = new MailAddress(item.ToAddress, item.ToName);
}
catch
{
throw new Exception($"收件地址{item.ToAddress},格式错误");
}
EmailPool<G> emailPool = new EmailPool<G>();
emailPool.PopulateWith(item);
conn.Insert(emailPool);
rtns.Add(emailPool);
}
catch
{
continue;
}
}
return rtns;
}
public static List<EmailPool<G>> GetPreSending<G>(this IDbConnection conn)
{
if (conn == null) conn = KiviiContext.GetOpenedDbConnection<EmailPool<G>>();
var rtns = conn.Select<EmailPool<G>>(o => o.IsSended == false);
return rtns;
}
public static List<EmailPool<G>> SendComplete<G>(this List<EmailPool<G>> items, string operatorName=null, Guid? operatorKvid=null, IDbConnection conn = null)
{
var rtns = new List<EmailPool<G>>();
if (conn == null) conn = KiviiContext.GetOpenedDbConnection<EmailPool<G>>();
if (operatorName.IsNullOrEmpty())
{
operatorName = KiviiContext.CurrentMember.FullName;
operatorKvid = KiviiContext.CurrentMember.Kvid;
}
foreach (var item in items)
{
item.IsSended = true;
item.AddOnlyProperties(o => o.IsSended);
item.OperatorName = operatorName;
item.AddOnlyProperties(o => o.OperatorName);
if (operatorKvid != null)
{
item.OperatorKvid = operatorKvid.Value;
item.AddOnlyProperties(o => o.OperatorKvid);
}
item.Category = "发送成功";
item.AddOnlyProperties(o => o.Category);
//item.Remark = "";
//item.AddOnlyProperties(o => o.Remark);
conn.UpdateOnly(item);
rtns.Add(item);
var log = new EntityLog<G>();
log.OwnerKvid = item.OwnerKvid;
log.BizId = item.OwnerName;
log.BizKvid = item.OwnerKvid;
log.BizType = typeof(G).FullName;
log.Type = "电子邮箱";
log.Title = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
log.Summary = "电子邮箱发送完成";
log.Remark = $"[发送成功] 已成功将{item.OwnerName} 发送至客户邮箱({item.ToAddress}). 时间:{DateTime.Now:yyyy-MM-dd HH:mm:ss}!";
conn.Insert(log);
}
return rtns;
}
public static List<EmailPool<G>> SendFail<G>(this List<EmailPool<G>> items, string operatorName = null, Guid? operatorKvid = null, IDbConnection conn = null)
{
var rtns = new List<EmailPool<G>>();
if (conn == null) conn = KiviiContext.GetOpenedDbConnection<EmailPool<G>>();
if (operatorName.IsNullOrEmpty())
{
operatorName = KiviiContext.CurrentMember.FullName;
operatorKvid = KiviiContext.CurrentMember.Kvid;
}
foreach (var item in items)
{
item.IsSended = true;
item.AddOnlyProperties(o => o.IsSended);
item.OperatorName = operatorName;
item.AddOnlyProperties(o => o.OperatorName);
if (operatorKvid != null)
{
item.OperatorKvid = operatorKvid.Value;
item.AddOnlyProperties(o => o.OperatorKvid);
}
item.Category = $"发送失败";
item.AddOnlyProperties(o => o.Category);
item.AddOnlyProperties(o => o.Remark);
conn.UpdateOnly(item);
rtns.Add(item);
var log = new EntityLog<G>();
log.OwnerKvid = item.OwnerKvid;
log.BizId = item.OwnerName;
log.BizKvid = item.OwnerKvid;
log.BizType = typeof(G).FullName;
log.Type = "电子邮箱";
log.Title = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
log.Summary = "电子邮箱发送失败";
log.Remark = $"[发送失败] 发送{item.ToAddress}失败原因:{item.Remark}. 时间:{DateTime.Now:yyyy-MM-dd HH:mm:ss}!";
conn.Insert(log);
}
return rtns;
}
public static List<EmailPool<G>> SendCancel<G>(this List<EmailPool<G>> items, string operatorName = null, Guid? operatorKvid = null, bool isDelete=false, IDbConnection conn = null)
{
var rtns = new List<EmailPool<G>>();
if (conn == null) conn = KiviiContext.GetOpenedDbConnection<EmailPool<G>>();
if (operatorName.IsNullOrEmpty())
{
operatorName = KiviiContext.CurrentMember.FullName;
operatorKvid = KiviiContext.CurrentMember.Kvid;
}
foreach (var item in items)
{
if (isDelete)
{
item.Status = -1;
item.AddOnlyProperties(o => o.Status);
conn.UpdateOnly(item);
rtns.Add(item);
continue;
}
if (item.IsSended) continue;
item.IsSended = true;
item.AddOnlyProperties(o => o.IsSended);
item.OperatorName = operatorName;
item.AddOnlyProperties(o => o.OperatorName);
if (operatorKvid != null)
{
item.OperatorKvid = operatorKvid.Value;
item.AddOnlyProperties(o => o.OperatorKvid);
}
item.Category = $"取消发送";
item.AddOnlyProperties(o => o.Category);
conn.UpdateOnly(item);
rtns.Add(item);
var log = new EntityLog<G>();
log.OwnerKvid = item.OwnerKvid;
log.BizId = item.OwnerName;
log.BizKvid = item.OwnerKvid;
log.BizType = typeof(G).FullName;
log.Type = "电子邮箱";
log.Title = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
log.Summary = "取消电子邮箱发送";
log.Remark = $"[取消发送] 操作人:{KiviiContext.CurrentMember.FullName}. 时间:{DateTime.Now:yyyy-MM-dd HH:mm:ss}!";
conn.Insert(log);
}
return rtns;
}
}
}
......@@ -53,6 +53,7 @@
<ItemGroup>
<Compile Include="Configs.cs" />
<Compile Include="Entities\EmailPool.cs" />
<Compile Include="Extension.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Transforms\RestfulEmailPool.cs" />
</ItemGroup>
......
......@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("5.4.2024.11070")]
[assembly: AssemblyFileVersion("5.4.2023.11070")]
\ No newline at end of file
[assembly: AssemblyVersion("5.4.2025.2190")]
[assembly: AssemblyFileVersion("5.4.2025.2190")]
\ No newline at end of file
......@@ -30,41 +30,8 @@ namespace Kivii.EmailPools.Transforms
var rtns = new RestfulCreateResponse<EmailPool<G>>();
rtns.Results = new List<EmailPool<G>>();
foreach (var item in Items)
{
try
{
//try
//{
// Console.WriteLine($"-----------------------from:{item.FromAddress}---------------------------------");
// var from = new MailAddress(item.FromAddress, item.FromAddress);
//}
//catch
//{
// Console.WriteLine($"-----------------------fromCatch:{item.FromAddress}---------------------------------");
// throw new Exception($"发送地址{item.FromAddress},格式错误");
//}
try
{
Console.WriteLine($"-----------------------To:{item.ToAddress}---------------------------------");
var to = new MailAddress(item.ToAddress, item.ToName);
}
catch
{
Console.WriteLine($"-----------------------ToCatch:{item.ToAddress}---------------------------------");
throw new Exception($"收件地址{item.ToAddress},格式错误");
}
EmailPool<G> emailPool = new EmailPool<G>();
emailPool.PopulateWith(item);
conn.Insert(emailPool);
Console.WriteLine("-----------------------EmailCreateEnd---------------------------------");
rtns.Results.Add(emailPool);
}
catch
{
continue;
}
}
var results = Items.Accept<G>(conn);
rtns.Results.AddRange(results);
return rtns;
}
}
......@@ -99,7 +66,7 @@ namespace Kivii.EmailPools.Transforms
foreach (var item in Items)
{
var emailPool = emailPools.FirstOrDefault(o => o.Kvid == item.Kvid);
if(emailPool != null)
if (emailPool != null)
{
if (item.OnlyPropertiesIsExist(o => o.ToAddress))
{
......@@ -168,11 +135,11 @@ namespace Kivii.EmailPools.Transforms
public override object OnExecutionGeneric<G>(IRequest req, IResponse res)
{
var conn = KiviiContext.GetOpenedDbConnection<EmailPool<G>>();
var pools = conn.Select<EmailPool<G>>(o => o.IsSended == false);
var rtns = new RestfulQueryResponse<EmailPool<G>>();
rtns.Results = new List<EmailPool<G>>();
rtns.Results.AddRange(pools);
rtns.Results = conn.GetPreSending<G>();
rtns.Total = rtns.Results.Count;
return rtns;
......@@ -197,33 +164,7 @@ namespace Kivii.EmailPools.Transforms
var rtns = new RestfulExecutionResponse<EmailPool<G>>();
rtns.Results = new List<EmailPool<G>>();
foreach (var item in pools)
{
item.IsSended = true;
item.AddOnlyProperties(o => o.IsSended);
item.OperatorName = OperatorName;
item.AddOnlyProperties(o => o.OperatorName);
item.OperatorKvid = OperatorKvid;
item.AddOnlyProperties(o => o.OperatorKvid);
//item.Category = "发送成功";
//item.AddOnlyProperties(o => o.Category);
//item.Remark = "";
//item.AddOnlyProperties(o => o.Remark);
conn.UpdateOnly(item);
rtns.Results.Add(item);
var log = new EntityLog<G>();
log.OwnerKvid = item.OwnerKvid;
log.BizId = item.OwnerName;
log.BizKvid = item.OwnerKvid;
log.BizType = typeof(G).FullName;
log.Type = "电子邮箱";
log.Title = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
log.Summary = "电子邮箱发送完成";
log.Remark = $"[发送成功] 已成功将{item.OwnerName} 发送至客户邮箱({item.ToAddress}). 时间:{DateTime.Now:yyyy-MM-dd HH:mm:ss}!";
conn.Insert(log);
}
rtns.Results = pools.SendComplete<G>(OperatorName, OperatorKvid, conn);
return rtns;
}
......@@ -253,30 +194,9 @@ namespace Kivii.EmailPools.Transforms
{
var current = Items.FirstOrDefault(o => o.Kvid == item.Kvid);
if (current == null) continue;
item.IsSended = true;
item.AddOnlyProperties(o => o.IsSended);
item.OperatorName = OperatorName;
item.AddOnlyProperties(o => o.OperatorName);
item.OperatorKvid = OperatorKvid;
item.AddOnlyProperties(o => o.OperatorKvid);
//item.Category = $"发送失败";
//item.AddOnlyProperties(o => o.Category);
item.Remark = current.Remark;
item.AddOnlyProperties(o => o.Remark);
conn.UpdateOnly(item);
rtns.Results.Add(item);
var log = new EntityLog<G>();
log.OwnerKvid = item.OwnerKvid;
log.BizId = item.OwnerName;
log.BizKvid = item.OwnerKvid;
log.BizType = typeof(G).FullName;
log.Type = "电子邮箱";
log.Title = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
log.Summary = "电子邮箱发送失败";
log.Remark = $"[发送失败] 发送{item.ToAddress}失败原因:{item.Remark}. 时间:{DateTime.Now:yyyy-MM-dd HH:mm:ss}!";
conn.Insert(log);
}
rtns.Results = pools.SendFail<G>(OperatorName, OperatorKvid, conn);
return rtns;
}
......@@ -288,7 +208,8 @@ namespace Kivii.EmailPools.Transforms
{
public List<Guid> Kvids { get; set; }
public bool IsDelete { get; set; } = false;
public string OperatorName { get; set; }
public Guid OperatorKvid { get; set; }
public override object OnExecutionGeneric<G>(IRequest req, IResponse res)
{
Kvids.ThrowIfNullOrEmpty("Need Kvids");
......@@ -299,40 +220,7 @@ namespace Kivii.EmailPools.Transforms
var rtns = new RestfulExecutionResponse<EmailPool<G>>();
rtns.Results = new List<EmailPool<G>>();
foreach (var item in pools)
{
if (IsDelete)
{
item.Status = -1;
item.AddOnlyProperties(o => o.Status);
conn.UpdateOnly(item);
rtns.Results.Add(item);
continue;
}
if (item.IsSended) continue;
item.IsSended = true;
item.AddOnlyProperties(o => o.IsSended);
item.OperatorName = KiviiContext.CurrentMember.FullName;
item.AddOnlyProperties(o => o.OperatorName);
item.OperatorKvid = KiviiContext.CurrentMember.Kvid;
item.AddOnlyProperties(o => o.OperatorKvid);
//item.Category = $"取消发送";
//item.AddOnlyProperties(o => o.Category);
conn.UpdateOnly(item);
rtns.Results.Add(item);
var log = new EntityLog<G>();
log.OwnerKvid = item.OwnerKvid;
log.BizId = item.OwnerName;
log.BizKvid = item.OwnerKvid;
log.BizType = typeof(G).FullName;
log.Type = "电子邮箱";
log.Title = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
log.Summary = "取消电子邮箱发送";
log.Remark = $"[取消发送] 操作人:{KiviiContext.CurrentMember.FullName}. 时间:{DateTime.Now:yyyy-MM-dd HH:mm:ss}!";
conn.Insert(log);
}
rtns.Results = pools.SendCancel<G>(OperatorName, OperatorKvid, IsDelete, conn);
return rtns;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment