fix 优化余额迁移,获取设备权限tenantId

This commit is contained in:
2024-07-11 10:00:05 +08:00
parent e6fbdfa730
commit d5ed47eb2e
4 changed files with 41 additions and 10 deletions

View File

@@ -68,7 +68,6 @@ public class GainfoMealService : IGainfoMealService
return page;
}
/// <inheritdoc />
public async Task MigrationAsync(GainfoBalanceMigrationRequest request)
{
//只能针对离职人员
@@ -81,20 +80,53 @@ public class GainfoMealService : IGainfoMealService
return;
}
//清空余额
var now = DateTime.Now;
await _dbContext.InsertAsync(new BalanceRecordEntity
{
No = SnowFlakeHelper.Instance.NextId().ToString(),
UserNo = gainfoLeave.No,
Name = gainfoLeave.Name,
UserCode = gainfoLeave.Code,
DepartmentNo = gainfoLeave.DepartmentNo,
Source = BalanceRecordSourceEnumType.BalanceMigration,
Type = BalanceRecordTypeEnumType.In,
Amount = -Math.Abs(beforeBalance),
BusinessPlaceCode = null,
BusinessShiftCode = null,
ShiftType = null,
CostDate = now.Date,
DeviceUniqueNo = null,
SubsidiesFromMonth = now.ToString("yyyyMM"),
IP = null,
CostId = gainfoLeave.CostId,
OriginTenantId = gainfoLeave.Factory,
IsCostCrossTenant = false,
Status = BalanceRecordStatusEnumType.Valid,
CostDateTime = DateTime.Now,
Remark = $"{gainfoLeave.Code}:余额转出",
ApplicationType = CanteenApplicationTypeEnumType.BalanceMigration,
TenantId = gainfoLeave.Factory,
Werks = gainfoLeave.Werks,
IsDeleted = false,
});
var beforeBalanceAmount = await _dbContext.Queryable<BalanceRecordEntity>()
.Where(x => x.UserCode == gainfoLeave.Code)
.Where(x => x.Status == BalanceRecordStatusEnumType.Valid)
.SumAsync(x => x.Amount);
await _dbContext.Updateable<GainfoMealEntity>()
.SetColumns(x => x.Balance == 0)
.SetColumns(x => x.Balance == beforeBalanceAmount)
.SetColumns(x => x.ModifiedTime == DateTime.Now)
.SetColumns(x => x.Version == x.Version + 1)
.Where(x => x.UserCode == request.BeforeCode) //不需要判断version
.ExecuteCommandAsync();
//转移到现有人员
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == request.NowCode).SingleAsync();
gainfo.ThrowIfNull("目标人员不存在");
var now = DateTime.Now;
await _dbContext.InsertAsync(new BalanceRecordEntity
{
No = SnowFlakeHelper.Instance.NextId().ToString(),
@@ -126,6 +158,7 @@ public class GainfoMealService : IGainfoMealService
var nowGainfoMeal = await _dbContext.Queryable<GainfoMealEntity>().Where(x => x.UserCode == request.NowCode).SingleAsync();
var nowBalance = nowGainfoMeal.Balance + beforeBalance;
await _dbContext.Updateable<GainfoMealEntity>()
.SetColumns(x => x.Balance == nowBalance)
.SetColumns(x => x.ModifiedTime == DateTime.Now)