using System.Reflection;
using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Canteen.Entities;
using Dlhis.Entity.Canteen.Enums;
using Kurisu.AspNetCore;
using Kurisu.AspNetCore.DataAccess.Entity;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
using SqlSugar;
namespace Dlhis.Basic.Common.SysData.Services.Implements;
public class SysDataService : ISysDataService
{
private readonly IDbContext _dbContext;
public SysDataService(IDbContext dbContext)
{
_dbContext = dbContext;
}
///
public async Task> DownloadAsync(string factory, string tableName)
{
var type = App.ActiveTypes
.Where(x => x.IsDefined(typeof(SugarTable), false))
.Where(x => !x.IsDefined(typeof(SkipScanAttribute), false))
.First(x => x.GetCustomAttribute()!.TableName == tableName);
var table = type.GetCustomAttribute()!.TableName;
var sql = $"select * from {table}";
if (type.IsAssignableTo(typeof(ITenantId)))
{
sql += $" where tenantId = '{factory}'";
}
switch (tableName)
{
case "Gainfo":
return await _dbContext.Queryable().Where(x => x.Factory == factory).Select(x => (object)x).ToListAsync();
case "GainfoMeal":
{
var factories = await GetWalletFactoriesAsync(factory);
var codes = await _dbContext.Queryable().Where(x => x.Factory == factory).Select(x => x.Code).ToListAsync();
// return await _dbContext.Queryable()
// .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;
}
default:
return await _dbContext.Client.SqlQueryable