feat 重算

This commit is contained in:
2024-07-02 11:12:25 +08:00
parent e9f71bcef3
commit 80e92d0019
4 changed files with 66 additions and 1 deletions

View File

@@ -686,6 +686,45 @@ public class BalanceService : IBalanceService
}
}
public async Task ReCalcAsync(BalanceReCalcRequest request)
{
await CommonHelper.RetryAsync(async () =>
{
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == request.UserCode).SingleAsync();
gainfo.ThrowIfNull("档案不存在");
var gainfoMeal = await _dbContext.Queryable<GainfoMealEntity>().Where(x => x.UserCode == gainfo.Code).FirstAsync();
if (gainfoMeal == null)
{
gainfoMeal = new GainfoMealEntity
{
UserNo = gainfo.No,
UserCode = gainfo.Code,
Balance = 0,
BalanceOfRecharge = 0,
BalanceOfSubsidies = 0,
Version = 0
};
await _dbContext.InsertAsync(gainfoMeal);
}
//重新核算
var balance = await _dbContext.Queryable<BalanceRecordEntity>()
.Where(x => x.UserCode == gainfo.Code)
.Where(x => x.Status == BalanceRecordStatusEnumType.Valid)
.SumAsync(x => x.Amount);
await _dbContext.Updateable<GainfoMealEntity>()
.SetColumns(x => x.Version == x.Version + 1)
.SetColumns(x => x.Balance == balance)
.SetColumns(x => x.ModifiedTime == DateTime.Now)
.Where(x => x.UserCode == gainfoMeal.UserCode && x.Version == gainfoMeal.Version)
.ExecuteCommandThrowVersionAsync();
}, 5);
}
/// <summary>
/// 获取离线设备