feat 重算
This commit is contained in:
@@ -36,4 +36,6 @@ public interface IBalanceService : IScopeDependency
|
||||
Task<List<BalanceHainingDownloadResponse>> HainingDownloadAsync(string userCode);
|
||||
|
||||
Task ManuallyImportBalanceAndReCalcAsync(List<BalanceManuallyImportRequest> requests);
|
||||
|
||||
Task ReCalcAsync(BalanceReCalcRequest request);
|
||||
}
|
||||
@@ -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>
|
||||
/// 获取离线设备
|
||||
|
||||
Reference in New Issue
Block a user