fix 消费恢复为余额表

This commit is contained in:
2024-11-21 10:27:08 +08:00
parent 2a97798118
commit 484be10fde
8 changed files with 168 additions and 36 deletions

View File

@@ -6,6 +6,8 @@ using Dlhis.ScheduledTask.Attributes;
using Dlhis.ScheduledTask.Common.Request;
using Dlhis.ScheduledTask.Common.Services;
using Hangfire;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
using Kurisu.AspNetCore.Utils;
namespace Dlhis.ScheduledTask.Jobs;
@@ -119,7 +121,39 @@ public class MealSupplementHandlerJob : BaseJob
IsDeleted = false,
});
if (!await DbContext.Queryable<UserBalanceEntity>().Where(x => x.UserCode == gainfo.Code).AnyAsync())
{
await DbContext.InsertAsync(new UserBalanceEntity
{
UserCode = gainfo.Code,
Balance = 0,
Version = 0
});
}
await CommonHelper.RetryAsync(async () =>
{
var balance = await DbContext.Queryable<BalanceRecordEntity>()
.Where(x => x.UserCode == gainfo.Code)
.Where(x => x.Status == BalanceRecordStatusEnumType.Valid)
.Where(x => x.Source != BalanceRecordSourceEnumType.EMealVoucher)
.SumAsync(x => x.Amount);
var version = await DbContext.Queryable<UserBalanceEntity>()
.Where(x => x.UserCode == gainfo.Code)
.Select(x => x.Version)
.SingleAsync();
await DbContext.Updateable<UserBalanceEntity>()
.SetColumns(x => x.Balance == balance)
.SetColumns(x => x.Version == version + 1)
.SetColumns(x => x.ModifiedTime == DateTime.Now)
.Where(x => x.UserCode == gainfo.Code && x.Version == version)
.ExecuteCommandThrowVersionAsync();
}, 5);
var r = await _jinkoJIPService.SyncMealSupplementRecordsAsync(new List<SyncMealSupplementRecordRequest>
{
new()