Commit e75d3231 by 陶然

优化使用到了Cache的接口

parent cf5a051b
...@@ -33,5 +33,5 @@ using System.Runtime.InteropServices; ...@@ -33,5 +33,5 @@ using System.Runtime.InteropServices;
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示: //通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("5.4.2023.4190")] [assembly: AssemblyVersion("5.4.2023.9040")]
[assembly: AssemblyFileVersion("5.4.2023.4190")] [assembly: AssemblyFileVersion("5.4.2023.9040")]
...@@ -264,6 +264,22 @@ namespace Kivii.Finances.Transforms ...@@ -264,6 +264,22 @@ namespace Kivii.Finances.Transforms
(Payments.Exists(o => o.Amount <= 0)).ThrowIfTrue("未指定到账开票金额!"); (Payments.Exists(o => o.Amount <= 0)).ThrowIfTrue("未指定到账开票金额!");
(Payments.Sum(o => o.Amount) != Items.Sum(o => o.Amount)).ThrowIfTrue("到账开票金额和发票金额不一致!"); (Payments.Sum(o => o.Amount) != Items.Sum(o => o.Amount)).ThrowIfTrue("到账开票金额和发票金额不一致!");
} }
#region 启用缓存,将当前人创建批次数据存入,处理完毕或者接口报错后清除,确保不会重复创建
var cache = KiviiContext.GetCacheClient();
var cacheKey = KiviiContext.GetUrnKey($"{this.GetType().FullName}_Request_{KiviiContext.CurrentMember.FullName}_{KiviiContext.CurrentMember.Kvid}");
var cacheValue = cache.Get<int?>(cacheKey);
if (cacheValue != null)
{
if (cacheValue < 0) throw new Exception($"仍在处理中,请稍后查看结果!");
else throw new Exception($"当前正在处理中,剩余{cacheValue}条,请稍后查看结果!");
}
int? caches = Items.Count;
//caches.AddRange(Items.ConvertAll(o => o.SerialNumber));
cache.Set(cacheKey, caches, TimeSpan.FromMinutes(5));
#endregion
try
{
var conn = KiviiContext.GetOpenedDbConnection<Invoice>(); var conn = KiviiContext.GetOpenedDbConnection<Invoice>();
//var exists = conn.Select<Invoice>(o => Sql.In(o.SerialNumber, Items.ConvertAll(p => p.SerialNumber))); //var exists = conn.Select<Invoice>(o => Sql.In(o.SerialNumber, Items.ConvertAll(p => p.SerialNumber)));
//(conn.Exists<Invoice>(o => Sql.In(o.SerialNumber, Items.ConvertAll(p => p.SerialNumber)))).ThrowIfTrue("存在重复录入的发票信息"); //(conn.Exists<Invoice>(o => Sql.In(o.SerialNumber, Items.ConvertAll(p => p.SerialNumber)))).ThrowIfTrue("存在重复录入的发票信息");
...@@ -321,7 +337,7 @@ namespace Kivii.Finances.Transforms ...@@ -321,7 +337,7 @@ namespace Kivii.Finances.Transforms
invoice.Type = info.Type; invoice.Type = info.Type;
invoice.Category = info.Category.IsNullOrEmpty() ? category.ToString() : info.Category; invoice.Category = info.Category.IsNullOrEmpty() ? category.ToString() : info.Category;
invoice.OperateTime = info.OperateTime; invoice.OperateTime = info.OperateTime;
invoice.SerialCode = info.SerialCode ; invoice.SerialCode = info.SerialCode;
invoice.SerialNumber = info.SerialNumber; invoice.SerialNumber = info.SerialNumber;
//invoice.Status = 1; //invoice.Status = 1;
invoice.TaxRate = info.TaxRate; invoice.TaxRate = info.TaxRate;
...@@ -380,18 +396,6 @@ namespace Kivii.Finances.Transforms ...@@ -380,18 +396,6 @@ namespace Kivii.Finances.Transforms
} }
var rtns = new RestfulUpdateResponse<Invoice>(); var rtns = new RestfulUpdateResponse<Invoice>();
rtns.Results = new List<Invoice>(); rtns.Results = new List<Invoice>();
#region 启用缓存,将当前人创建批次数据存入,处理完毕或者接口报错后清除,确保不会重复创建
var cache = KiviiContext.GetCacheClient();
var cacheKey = KiviiContext.GetUrnKey($"{this.GetType().FullName}_Request_{KiviiContext.CurrentMember.FullName}_{KiviiContext.CurrentMember.Kvid}");
var cacheValue = cache.Get<List<string>>(cacheKey);
if (!cacheValue.IsNullOrEmpty())
{
throw new Exception($"当前正在处理中,剩余{cacheValue.Count}条,请稍后再试!");
}
var caches = new List<string>();
caches.AddRange(insertInvoices.ConvertAll(o => o.SerialNumber));
cache.Set(cacheKey, caches, TimeSpan.FromMinutes(5));
#endregion
var trans = conn.OpenTransaction(); var trans = conn.OpenTransaction();
try try
{ {
...@@ -402,7 +406,7 @@ namespace Kivii.Finances.Transforms ...@@ -402,7 +406,7 @@ namespace Kivii.Finances.Transforms
if (item.Type == "Relation") item.SerialNumber = item.GetSubSerialNumber(conn); if (item.Type == "Relation") item.SerialNumber = item.GetSubSerialNumber(conn);
conn.Insert(item); conn.Insert(item);
if (item.Type != "Relation") rtns.Results.Add(item); if (item.Type != "Relation") rtns.Results.Add(item);
caches.Remove(item.SerialNumber); caches--;
cache.Replace(cacheKey, caches); cache.Replace(cacheKey, caches);
} }
} }
...@@ -426,5 +430,11 @@ namespace Kivii.Finances.Transforms ...@@ -426,5 +430,11 @@ namespace Kivii.Finances.Transforms
throw ex; throw ex;
} }
} }
catch (Exception ex)
{
cache.Remove(cacheKey);
throw ex;
}
}
} }
} }
...@@ -27,7 +27,22 @@ namespace Kivii.Finances.Transforms ...@@ -27,7 +27,22 @@ namespace Kivii.Finances.Transforms
PayingMethods.Exists(o => o.Kvid == Guid.Empty).ThrowIfTrue("付款登记Kvid不能为空!"); PayingMethods.Exists(o => o.Kvid == Guid.Empty).ThrowIfTrue("付款登记Kvid不能为空!");
(PayingMethods.Count(o => o.Type == PayType.Discount) > 1).ThrowIfTrue("金额抵扣登记方式超过限制次数,仅可使用一次"); (PayingMethods.Count(o => o.Type == PayType.Discount) > 1).ThrowIfTrue("金额抵扣登记方式超过限制次数,仅可使用一次");
var amountMethod = PayingMethods.Sum(o => o.Amount); var amountMethod = PayingMethods.Sum(o => o.Amount);
#region 启用缓存,将当前人创建批次数据存入,处理完毕或者接口报错后清除,确保不会重复创建
var cache = KiviiContext.GetCacheClient();
var cacheKey = KiviiContext.GetUrnKey($"{this.GetType().FullName}_Request_{KiviiContext.CurrentMember.FullName}_{KiviiContext.CurrentMember.Kvid}");
var cacheValue = cache.Get<int?>(cacheKey);
if (cacheValue != null)
{
if (cacheValue < 0) throw new Exception($"仍在处理中,请稍后查看结果!");
else throw new Exception($"当前正在处理中,剩余{cacheValue}条,请稍后查看结果!");
}
int? caches = SettlementKvids.Count;
//caches.AddRange(Items.ConvertAll(o => o.SerialNumber));
cache.Set(cacheKey, caches, TimeSpan.FromMinutes(5));
#endregion
try
{
var conn = KiviiContext.GetOpenedDbConnection<Pay>(); var conn = KiviiContext.GetOpenedDbConnection<Pay>();
var settlements = conn.Select<Settlement>(o => Sql.In(o.Kvid, SettlementKvids)); var settlements = conn.Select<Settlement>(o => Sql.In(o.Kvid, SettlementKvids));
settlements.ThrowIfNullOrEmpty("未找到结算单!"); settlements.ThrowIfNullOrEmpty("未找到结算单!");
...@@ -49,19 +64,6 @@ namespace Kivii.Finances.Transforms ...@@ -49,19 +64,6 @@ namespace Kivii.Finances.Transforms
var accountBiz = currency.GetBizAccount();//conn.Single<Account>(o => o.OwnerKvid == KiviiContext.CurrentMember.OrganizationKvid && o.Type == AccountType.Biz && o.Currency == Item.Currency); var accountBiz = currency.GetBizAccount();//conn.Single<Account>(o => o.OwnerKvid == KiviiContext.CurrentMember.OrganizationKvid && o.Type == AccountType.Biz && o.Currency == Item.Currency);
accountBiz.ThrowIfNull($"未能正确获取系统{currency}业务账户!请联系管理员!"); accountBiz.ThrowIfNull($"未能正确获取系统{currency}业务账户!请联系管理员!");
#region 启用缓存,将当前人创建批次数据存入,处理完毕或者接口报错后清除,确保不会重复创建
var cache = KiviiContext.GetCacheClient();
var cacheKey = KiviiContext.GetUrnKey($"{this.GetType().FullName}_Request_{KiviiContext.CurrentMember.FullName}_{KiviiContext.CurrentMember.Kvid}");
var cacheValue = cache.Get<List<string>>(cacheKey);
if (!cacheValue.IsNullOrEmpty())
{
throw new Exception($"当前正在处理中,剩余{cacheValue.Count}条,请稍后再试!");
}
var caches = new List<string>();
caches.AddRange(settlements.ConvertAll(o => o.BizId));
cache.Set(cacheKey, caches, TimeSpan.FromMinutes(5));
#endregion
if (PayingMethods.Count == 1)//单笔付款登记 if (PayingMethods.Count == 1)//单笔付款登记
{ {
using (KiviiContext.Profiler("单个方式收款")) using (KiviiContext.Profiler("单个方式收款"))
...@@ -100,7 +102,7 @@ namespace Kivii.Finances.Transforms ...@@ -100,7 +102,7 @@ namespace Kivii.Finances.Transforms
foreach (var item in settlements) foreach (var item in settlements)
{ {
if (!item.OnlyProperties.IsNullOrEmpty()) conn.UpdateOnly(item);//更新了AmountPayment if (!item.OnlyProperties.IsNullOrEmpty()) conn.UpdateOnly(item);//更新了AmountPayment
caches.Remove(item.BizId); caches--;
cache.Replace(cacheKey, caches); cache.Replace(cacheKey, caches);
} }
var groupSettlement = settlements.GroupBy(o => o.BizType); var groupSettlement = settlements.GroupBy(o => o.BizType);
...@@ -159,7 +161,7 @@ namespace Kivii.Finances.Transforms ...@@ -159,7 +161,7 @@ namespace Kivii.Finances.Transforms
foreach (var item in settlements) foreach (var item in settlements)
{ {
if (!item.OnlyProperties.IsNullOrEmpty()) conn.UpdateOnly(item);//更新了Paykvid和AmountPayment if (!item.OnlyProperties.IsNullOrEmpty()) conn.UpdateOnly(item);//更新了Paykvid和AmountPayment
caches.Remove(item.BizId); caches--;
cache.Replace(cacheKey, caches); cache.Replace(cacheKey, caches);
} }
var groupSettlement = settlements.GroupBy(o => o.BizType); var groupSettlement = settlements.GroupBy(o => o.BizType);
...@@ -216,7 +218,7 @@ namespace Kivii.Finances.Transforms ...@@ -216,7 +218,7 @@ namespace Kivii.Finances.Transforms
foreach (var item in settlements) foreach (var item in settlements)
{ {
if (!item.OnlyProperties.IsNullOrEmpty()) conn.UpdateOnly(item);//更新了Paykvid和AmountPayment if (!item.OnlyProperties.IsNullOrEmpty()) conn.UpdateOnly(item);//更新了Paykvid和AmountPayment
caches.Remove(item.BizId); caches--;
cache.Replace(cacheKey, caches); cache.Replace(cacheKey, caches);
} }
var groupSettlement = settlements.GroupBy(o => o.BizType); var groupSettlement = settlements.GroupBy(o => o.BizType);
...@@ -368,7 +370,7 @@ namespace Kivii.Finances.Transforms ...@@ -368,7 +370,7 @@ namespace Kivii.Finances.Transforms
foreach (var item in settlements) foreach (var item in settlements)
{ {
if (!item.OnlyProperties.IsNullOrEmpty()) conn.UpdateOnly(item);//更新了Paykvid和AmountPayment if (!item.OnlyProperties.IsNullOrEmpty()) conn.UpdateOnly(item);//更新了Paykvid和AmountPayment
caches.Remove(item.BizId); caches--;
cache.Replace(cacheKey, caches); cache.Replace(cacheKey, caches);
} }
var groupSettlement = settlements.GroupBy(o => o.BizType); var groupSettlement = settlements.GroupBy(o => o.BizType);
...@@ -402,6 +404,12 @@ namespace Kivii.Finances.Transforms ...@@ -402,6 +404,12 @@ namespace Kivii.Finances.Transforms
return rtns; return rtns;
} }
} }
catch (Exception ex)
{
cache.Remove(cacheKey);
throw ex;
}
}
private IDbTransaction onExecution<T>(IDbConnection conn, List<Settlement> settlements) where T : IEntity private IDbTransaction onExecution<T>(IDbConnection conn, List<Settlement> settlements) where T : IEntity
{ {
......
...@@ -31,6 +31,22 @@ namespace Kivii.Finances.Transforms ...@@ -31,6 +31,22 @@ namespace Kivii.Finances.Transforms
//if (Items.Exists(o => o.PayerAccountKvid == Guid.Empty && o.PayeeAccountKvid == Guid.Empty)) throw new Exception("收付款账户不能同时为空!"); //if (Items.Exists(o => o.PayerAccountKvid == Guid.Empty && o.PayeeAccountKvid == Guid.Empty)) throw new Exception("收付款账户不能同时为空!");
//if (Items.Exists(o => o.PayerAccountKvid != Guid.Empty && o.PayeeAccountKvid != Guid.Empty)) throw new Exception("收付款账户不能同时指定!"); //if (Items.Exists(o => o.PayerAccountKvid != Guid.Empty && o.PayeeAccountKvid != Guid.Empty)) throw new Exception("收付款账户不能同时指定!");
#region 启用缓存,将当前人创建批次数据存入,处理完毕或者接口报错后清除,确保不会重复创建
var cache = KiviiContext.GetCacheClient();
var cacheKey = KiviiContext.GetUrnKey($"{this.GetType().FullName}_Request_{KiviiContext.CurrentMember.FullName}_{KiviiContext.CurrentMember.Kvid}");
var cacheValue = cache.Get<int?>(cacheKey);
if (cacheValue != null)
{
if (cacheValue < 0) throw new Exception($"仍在处理中,请稍后查看结果!");
else throw new Exception($"当前正在处理中,剩余{cacheValue}条,请稍后查看结果!");
}
int? caches = Items.Count;
//caches.AddRange(Items.ConvertAll(o => o.SerialNumber));
cache.Set(cacheKey, caches, TimeSpan.FromMinutes(5));
#endregion
try
{
var typeBanks = Items.Where(o => o.Type == PaymentType.Bank).ToList(); var typeBanks = Items.Where(o => o.Type == PaymentType.Bank).ToList();
var typeCashs = Items.Where(o => o.Type == PaymentType.Cash).ToList(); var typeCashs = Items.Where(o => o.Type == PaymentType.Cash).ToList();
var typePoss = Items.Where(o => o.Type == PaymentType.Pos).ToList(); var typePoss = Items.Where(o => o.Type == PaymentType.Pos).ToList();
...@@ -201,19 +217,6 @@ namespace Kivii.Finances.Transforms ...@@ -201,19 +217,6 @@ namespace Kivii.Finances.Transforms
var rtns = new RestfulCreateResponse<Payment>(); var rtns = new RestfulCreateResponse<Payment>();
rtns.Results = new List<Payment>(); rtns.Results = new List<Payment>();
#region 启用缓存,将当前人创建批次数据存入,处理完毕或者接口报错后清除,确保不会重复创建
var cache = KiviiContext.GetCacheClient();
var cacheKey = KiviiContext.GetUrnKey($"{this.GetType().FullName}_Request_{KiviiContext.CurrentMember.FullName}_{KiviiContext.CurrentMember.Kvid}");
var cacheValue = cache.Get<List<string>>(cacheKey);
if (!cacheValue.IsNullOrEmpty())
{
throw new Exception($"当前正在处理中,剩余{cacheValue.Count}条,请稍后再试!");
}
var caches = new List<string>();
caches.AddRange(allAcceptPayments.ConvertAll(o => o.SerialNumber));
cache.Set(cacheKey, caches, TimeSpan.FromMinutes(5));
#endregion
var trans = conn.OpenTransaction(); var trans = conn.OpenTransaction();
try try
...@@ -225,7 +228,7 @@ namespace Kivii.Finances.Transforms ...@@ -225,7 +228,7 @@ namespace Kivii.Finances.Transforms
conn.Insert(item); conn.Insert(item);
item.RemoveAllOnlyProperties(); item.RemoveAllOnlyProperties();
rtns.Results.Add(item); rtns.Results.Add(item);
caches.Remove(item.SerialNumber); caches--;
cache.Replace(cacheKey, caches); cache.Replace(cacheKey, caches);
} }
} }
...@@ -248,6 +251,13 @@ namespace Kivii.Finances.Transforms ...@@ -248,6 +251,13 @@ namespace Kivii.Finances.Transforms
} }
return rtns; return rtns;
}
catch (Exception ex)
{
cache.Remove(cacheKey);
throw ex;
}
} }
} }
} }
...@@ -177,7 +177,22 @@ namespace Kivii.Finances.Transforms ...@@ -177,7 +177,22 @@ namespace Kivii.Finances.Transforms
public override object OnExecution(IRequest req, IResponse res) public override object OnExecution(IRequest req, IResponse res)
{ {
if (Kvids.IsNullOrEmpty()) throw new Exception("请选择要认领的收款!"); if (Kvids.IsNullOrEmpty()) throw new Exception("请选择要认领的收款!");
#region 启用缓存,将当前人创建批次数据存入,处理完毕或者接口报错后清除,确保不会重复创建
var cache = KiviiContext.GetCacheClient();
var cacheKey = KiviiContext.GetUrnKey($"{this.GetType().FullName}_Request_{KiviiContext.CurrentMember.FullName}_{KiviiContext.CurrentMember.Kvid}");
var cacheValue = cache.Get<int?>(cacheKey);
if (cacheValue != null)
{
if (cacheValue < 0) throw new Exception($"仍在处理中,请稍后查看结果!");
else throw new Exception($"当前正在处理中,剩余{cacheValue}条,请稍后查看结果!");
}
int? caches = Kvids.Count;
//caches.AddRange(Items.ConvertAll(o => o.SerialNumber));
cache.Set(cacheKey, caches, TimeSpan.FromMinutes(5));
#endregion
try
{
var conn = KiviiContext.GetOpenedDbConnection<Payment>(); var conn = KiviiContext.GetOpenedDbConnection<Payment>();
var payments = conn.SelectByIds<Payment>(Kvids); var payments = conn.SelectByIds<Payment>(Kvids);
...@@ -267,18 +282,6 @@ namespace Kivii.Finances.Transforms ...@@ -267,18 +282,6 @@ namespace Kivii.Finances.Transforms
var rtns = new RestfulExecutionResponse<Payment>(); var rtns = new RestfulExecutionResponse<Payment>();
rtns.Results = new List<Payment>(); rtns.Results = new List<Payment>();
#region 启用缓存,将当前人创建批次数据存入,处理完毕或者接口报错后清除,确保不会重复创建
var cache = KiviiContext.GetCacheClient();
var cacheKey = KiviiContext.GetUrnKey($"{this.GetType().FullName}_Request_{KiviiContext.CurrentMember.FullName}_{KiviiContext.CurrentMember.Kvid}");
var cacheValue = cache.Get<List<string>>(cacheKey);
if (!cacheValue.IsNullOrEmpty())
{
throw new Exception($"当前正在处理中,剩余{cacheValue.Count}条,请稍后再试!");
}
var caches = new List<string>();
caches.AddRange(splits.ConvertAll(o => o.SerialNumber));
cache.Set(cacheKey, caches, TimeSpan.FromMinutes(5));
#endregion
//开启事务进行数据库操作 //开启事务进行数据库操作
var trans = conn.OpenTransaction(); var trans = conn.OpenTransaction();
...@@ -288,7 +291,7 @@ namespace Kivii.Finances.Transforms ...@@ -288,7 +291,7 @@ namespace Kivii.Finances.Transforms
{ {
conn.Insert(split); conn.Insert(split);
rtns.Results.Add(split); rtns.Results.Add(split);
caches.Remove(split.SerialNumber); caches--;
cache.Replace(cacheKey, caches); cache.Replace(cacheKey, caches);
} }
foreach (var item in splitsSetOwner) foreach (var item in splitsSetOwner)
...@@ -316,6 +319,12 @@ namespace Kivii.Finances.Transforms ...@@ -316,6 +319,12 @@ namespace Kivii.Finances.Transforms
} }
return rtns; return rtns;
} }
catch (Exception ex)
{
cache.Remove(cacheKey);
throw ex;
}
}
} }
[Api(Description = "认领撤销")] [Api(Description = "认领撤销")]
...@@ -619,6 +628,22 @@ namespace Kivii.Finances.Transforms ...@@ -619,6 +628,22 @@ namespace Kivii.Finances.Transforms
{ {
if (Kvids.IsNullOrEmpty()) throw new Exception("请选择要划转的收款!"); if (Kvids.IsNullOrEmpty()) throw new Exception("请选择要划转的收款!");
#region 启用缓存,将当前人创建批次数据存入,处理完毕或者接口报错后清除,确保不会重复创建
var cache = KiviiContext.GetCacheClient();
var cacheKey = KiviiContext.GetUrnKey($"{this.GetType().FullName}_Request_{KiviiContext.CurrentMember.FullName}_{KiviiContext.CurrentMember.Kvid}");
var cacheValue = cache.Get<int?>(cacheKey);
if (cacheValue != null)
{
if (cacheValue < 0) throw new Exception($"仍在处理中,请稍后查看结果!");
else throw new Exception($"当前正在处理中,剩余{cacheValue}条,请稍后查看结果!");
}
int? caches = Kvids.Count;
//caches.AddRange(Items.ConvertAll(o => o.SerialNumber));
cache.Set(cacheKey, caches, TimeSpan.FromMinutes(5));
#endregion
try
{
var conn = KiviiContext.GetOpenedDbConnection<Payment>(); var conn = KiviiContext.GetOpenedDbConnection<Payment>();
var payments = conn.SelectByIds<Payment>(Kvids); var payments = conn.SelectByIds<Payment>(Kvids);
...@@ -673,19 +698,6 @@ namespace Kivii.Finances.Transforms ...@@ -673,19 +698,6 @@ namespace Kivii.Finances.Transforms
var rtns = new RestfulExecutionResponse<Payment>(); var rtns = new RestfulExecutionResponse<Payment>();
rtns.Results = new List<Payment>(); rtns.Results = new List<Payment>();
#region 启用缓存,将当前人创建批次数据存入,处理完毕或者接口报错后清除,确保不会重复创建
var cache = KiviiContext.GetCacheClient();
var cacheKey = KiviiContext.GetUrnKey($"{this.GetType().FullName}_Request_{KiviiContext.CurrentMember.FullName}_{KiviiContext.CurrentMember.Kvid}");
var cacheValue = cache.Get<List<string>>(cacheKey);
if (!cacheValue.IsNullOrEmpty())
{
throw new Exception($"当前正在处理中,剩余{cacheValue.Count}条,请稍后再试!");
}
var caches = new List<string>();
caches.AddRange(assigns.ConvertAll(o => o.SerialNumber));
cache.Set(cacheKey, caches, TimeSpan.FromMinutes(5));
#endregion
//开启事务进行数据库操作 //开启事务进行数据库操作
var trans = conn.OpenTransaction(); var trans = conn.OpenTransaction();
try try
...@@ -694,7 +706,7 @@ namespace Kivii.Finances.Transforms ...@@ -694,7 +706,7 @@ namespace Kivii.Finances.Transforms
{ {
conn.Insert(assign); conn.Insert(assign);
rtns.Results.Add(assign); rtns.Results.Add(assign);
caches.Remove(assign.SerialNumber); caches--;
cache.Replace(cacheKey, caches); cache.Replace(cacheKey, caches);
} }
foreach (var item in spliteds) foreach (var item in spliteds)
...@@ -712,6 +724,12 @@ namespace Kivii.Finances.Transforms ...@@ -712,6 +724,12 @@ namespace Kivii.Finances.Transforms
} }
return rtns; return rtns;
} }
catch (Exception ex)
{
cache.Remove(cacheKey);
throw ex;
}
}
} }
[Api(Description = "划转撤销")] [Api(Description = "划转撤销")]
......
...@@ -31,6 +31,24 @@ namespace Kivii.Finances.Transforms ...@@ -31,6 +31,24 @@ namespace Kivii.Finances.Transforms
bizKvids.RemoveAll(o => o == Guid.Empty); bizKvids.RemoveAll(o => o == Guid.Empty);
var bizids = Items.ConvertAll(p => p.BizId).Distinct().ToList(); var bizids = Items.ConvertAll(p => p.BizId).Distinct().ToList();
bizids.RemoveAll(o => o.IsNullOrEmpty()); bizids.RemoveAll(o => o.IsNullOrEmpty());
#region 启用缓存,将当前人创建批次数据存入,处理完毕或者接口报错后清除,确保不会重复创建
var cache = KiviiContext.GetCacheClient();
var cacheKey = KiviiContext.GetUrnKey($"{this.GetType().FullName}_Request_{KiviiContext.CurrentMember.FullName}_{KiviiContext.CurrentMember.Kvid}");
var cacheValue = cache.Get<int?>(cacheKey);
if (cacheValue != null)
{
if (cacheValue < 0) throw new Exception($"仍在处理中,请稍后查看结果!");
else throw new Exception($"当前正在处理中,剩余{cacheValue}条,请稍后查看结果!");
}
int? caches = Items.Count;
//caches.AddRange(Items.ConvertAll(o => o.SerialNumber));
cache.Set(cacheKey, caches, TimeSpan.FromMinutes(5));
#endregion
try
{
var connF = KiviiContext.GetOpenedDbConnection<Settlement>(); var connF = KiviiContext.GetOpenedDbConnection<Settlement>();
//foreach (var bizId in bizids) //foreach (var bizId in bizids)
//{ //{
...@@ -47,18 +65,6 @@ namespace Kivii.Finances.Transforms ...@@ -47,18 +65,6 @@ namespace Kivii.Finances.Transforms
//var detailBizids = allDetails.ConvertAll(p => p.BizId); //var detailBizids = allDetails.ConvertAll(p => p.BizId);
//detailBizids.RemoveAll(o => o.IsNullOrEmpty()); //detailBizids.RemoveAll(o => o.IsNullOrEmpty());
//if (connE.Exists<EntitySettlementDetail<G>>(o => o.OffsetKvid != Guid.Empty && (Sql.In(o.BizKvid, detailBizKvids) || Sql.In(o.BizId, detailBizids)))) throw new Exception("存在重复结算的明细项目!"); //if (connE.Exists<EntitySettlementDetail<G>>(o => o.OffsetKvid != Guid.Empty && (Sql.In(o.BizKvid, detailBizKvids) || Sql.In(o.BizId, detailBizids)))) throw new Exception("存在重复结算的明细项目!");
#region 启用缓存,将当前人创建批次数据存入,处理完毕或者接口报错后清除,确保不会重复创建
var cache = KiviiContext.GetCacheClient();
var cacheKey = KiviiContext.GetUrnKey($"{this.GetType().FullName}_Request_{KiviiContext.CurrentMember.FullName}_{KiviiContext.CurrentMember.Kvid}");
var cacheValue = cache.Get<List<string>>(cacheKey);
if (!cacheValue.IsNullOrEmpty())
{
throw new Exception($"当前正在处理中,剩余{cacheValue.Count}条,请稍后再试!");
}
var caches = new List<string>();
caches.AddRange(Items.ConvertAll(o => o.BizId));
cache.Set(cacheKey, caches, TimeSpan.FromMinutes(5));
#endregion
var rtns = new RestfulCreateResponse<Settlement>(); var rtns = new RestfulCreateResponse<Settlement>();
rtns.Results = new List<Settlement>(); rtns.Results = new List<Settlement>();
...@@ -192,7 +198,7 @@ namespace Kivii.Finances.Transforms ...@@ -192,7 +198,7 @@ namespace Kivii.Finances.Transforms
} }
connF.Insert(policyRecord); connF.Insert(policyRecord);
} }
caches.Remove(item.BizId); caches--;
cache.Replace(cacheKey, caches); cache.Replace(cacheKey, caches);
} }
} }
...@@ -210,6 +216,12 @@ namespace Kivii.Finances.Transforms ...@@ -210,6 +216,12 @@ namespace Kivii.Finances.Transforms
return rtns; return rtns;
} }
catch (Exception ex)
{
cache.Remove(cacheKey);
throw ex;
}
}
} }
[Api(Description = "泛型结算更新")] [Api(Description = "泛型结算更新")]
......
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