fix: 营销/代理分析查询改为串行,避免 MySQL 连接复用报错
All checks were successful
Build and Deploy / deploy (push) Successful in 1m20s
All checks were successful
Build and Deploy / deploy (push) Successful in 1m20s
同一作用域 SqlSugar 连接不能 Task.WhenAll 并发查询。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
6b00451914
commit
26ef78d01e
@ -182,16 +182,17 @@ public class AgentAnalysisService : ApplicationService
|
|||||||
DateTime endExclusive,
|
DateTime endExclusive,
|
||||||
bool usePayTime)
|
bool usePayTime)
|
||||||
{
|
{
|
||||||
var ordersTask = OrderRepository.ListAgentAnalysisOrdersByTimeRangeAsync(
|
// SqlSugar/MySQL 同一作用域连接不可并发复用,查询必须串行
|
||||||
|
var orders = await OrderRepository.ListAgentAnalysisOrdersByTimeRangeAsync(
|
||||||
start, endExclusive, usePayTime);
|
start, endExclusive, usePayTime);
|
||||||
var commissionsTask = DetailRepository.GetListAsync(x =>
|
var commissions = await DetailRepository.GetListAsync(x =>
|
||||||
x.CreateTime >= start && x.CreateTime < endExclusive);
|
x.CreateTime >= start && x.CreateTime < endExclusive);
|
||||||
var paidTask = DetailRepository.GetListAsync(x =>
|
var paidInPeriod = await DetailRepository.GetListAsync(x =>
|
||||||
x.Status == AgentCommissionStatusCodes.Paid
|
x.Status == AgentCommissionStatusCodes.Paid
|
||||||
&& x.PaidTime != null
|
&& x.PaidTime != null
|
||||||
&& x.PaidTime >= start
|
&& x.PaidTime >= start
|
||||||
&& x.PaidTime < endExclusive);
|
&& x.PaidTime < endExclusive);
|
||||||
var bindsTask = CustomerRepository.GetListAsync(x =>
|
var newBinds = await CustomerRepository.GetListAsync(x =>
|
||||||
x.ParentCustomerId == null
|
x.ParentCustomerId == null
|
||||||
&& x.AgentId != null
|
&& x.AgentId != null
|
||||||
&& x.AgentId > 0
|
&& x.AgentId > 0
|
||||||
@ -199,14 +200,12 @@ public class AgentAnalysisService : ApplicationService
|
|||||||
&& x.AgentBindTime >= start
|
&& x.AgentBindTime >= start
|
||||||
&& x.AgentBindTime < endExclusive);
|
&& x.AgentBindTime < endExclusive);
|
||||||
|
|
||||||
await Task.WhenAll(ordersTask, commissionsTask, paidTask, bindsTask);
|
|
||||||
|
|
||||||
return new PeriodBundle
|
return new PeriodBundle
|
||||||
{
|
{
|
||||||
Orders = await ordersTask,
|
Orders = orders,
|
||||||
Commissions = await commissionsTask,
|
Commissions = commissions,
|
||||||
PaidInPeriod = await paidTask,
|
PaidInPeriod = paidInPeriod,
|
||||||
NewBinds = await bindsTask
|
NewBinds = newBinds
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -105,21 +105,14 @@ public class MarketingAnalysisService : ApplicationService
|
|||||||
var (start, endExclusive, usePayTime) = NormalizeRange(input);
|
var (start, endExclusive, usePayTime) = NormalizeRange(input);
|
||||||
var topN = input.TopN <= 0 ? 20 : Math.Min(input.TopN, 100);
|
var topN = input.TopN <= 0 ? 20 : Math.Min(input.TopN, 100);
|
||||||
|
|
||||||
var issuedTask = InstanceRepository.ListReceivedInRangeAsync(start, endExclusive);
|
// SqlSugar/MySQL 同一作用域连接不可并发复用,查询必须串行
|
||||||
var usedTask = InstanceRepository.ListUsedInRangeAsync(start, endExclusive);
|
var issued = await InstanceRepository.ListReceivedInRangeAsync(start, endExclusive);
|
||||||
var expiredTask = InstanceRepository.ListExpiredInRangeAsync(start, endExclusive);
|
var used = await InstanceRepository.ListUsedInRangeAsync(start, endExclusive);
|
||||||
var availableTask = InstanceRepository.CountAvailableAsync();
|
var expired = await InstanceRepository.ListExpiredInRangeAsync(start, endExclusive);
|
||||||
var ordersTask = OrderRepository.ListMarketingSnapshotsByTimeRangeAsync(
|
var available = await InstanceRepository.CountAvailableAsync();
|
||||||
|
var orders = await OrderRepository.ListMarketingSnapshotsByTimeRangeAsync(
|
||||||
start, endExclusive, usePayTime);
|
start, endExclusive, usePayTime);
|
||||||
|
|
||||||
await Task.WhenAll(issuedTask, usedTask, expiredTask, availableTask, ordersTask);
|
|
||||||
|
|
||||||
var issued = await issuedTask;
|
|
||||||
var used = await usedTask;
|
|
||||||
var expired = await expiredTask;
|
|
||||||
var available = await availableTask;
|
|
||||||
var orders = await ordersTask;
|
|
||||||
|
|
||||||
var issuedCount = issued.Count;
|
var issuedCount = issued.Count;
|
||||||
var usedCount = used.Count;
|
var usedCount = used.Count;
|
||||||
var expiredCount = expired.Count;
|
var expiredCount = expired.Count;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user