fix gainfomeal处理

This commit is contained in:
2024-10-28 17:37:13 +08:00
parent e322d7e179
commit 3d8f9e1955

View File

@@ -24,35 +24,42 @@ public class SysDataService : ISysDataService
var type = App.ActiveTypes
.Where(x => x.IsDefined(typeof(SugarTable), false))
.Where(x => !x.IsDefined(typeof(SkipScanAttribute), false))
.First(x => x.GetCustomAttribute<SugarTable>()!.TableName == tableName);
.FirstOrDefault(x => x.GetCustomAttribute<SugarTable>()!.TableName == tableName);
var table = type.GetCustomAttribute<SugarTable>()!.TableName;
var table = type?.GetCustomAttribute<SugarTable>()!.TableName;
var sql = $"select * from {table}";
if (type.IsAssignableTo(typeof(ITenantId)))
if (type == null)
{
sql += $" where tenantId = '{factory}'";
table = tableName;
}
else
{
if (type.IsAssignableTo(typeof(ITenantId)))
{
sql += $" where tenantId = '{factory}'";
}
}
switch (tableName)
switch (table)
{
case "Gainfo":
return await _dbContext.Queryable<GainfoEntity>().Where(x => x.Factory == factory).Select(x => (object)x).ToListAsync();
case "GainfoMeal":
{
var factories = await GetWalletFactoriesAsync(factory);
var r = await _dbContext.Queryable<GainfoEntity>()
.LeftJoin<BalanceRecordEntity>((x, b) => x.Code == b.UserCode)
.Where(x => x.Factory == factory)
.Where((x, b) => b.Source != BalanceRecordSourceEnumType.EMealVoucher && b.Status == BalanceRecordStatusEnumType.Valid && b.IsDeleted == false)
.GroupBy(x => x.Code)
.Select((x, b) => new
{
UserCode = x.Code,
Balance = SqlFunc.AggregateSum(b.Amount)
})
.ToListAsync();
var codes = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Factory == factory).Select(x => x.Code).ToListAsync();
// return await _dbContext.Queryable<BalanceRecordEntity>()
// .Where(x => codes.Contains(x.UserCode) && factories.Contains(x.TenantId))
// .Where(x => x.Source != BalanceRecordSourceEnumType.EMealVoucher)
// .GroupBy(x => x.UserCode)
// .Select(x => new
// {
// x.UserCode,
// Balance = SqlFunc.AggregateSum(x.Amount)
// })
// .ToListAsync();
return null;
return r.Select(x => (object)x).ToList();
}
default:
return await _dbContext.Client.SqlQueryable<object>(sql).ToListAsync();