35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
using System.Reflection;
|
|
using Kurisu.AspNetCore;
|
|
using Kurisu.AspNetCore.DataAccess.Entity;
|
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
|
using SqlSugar;
|
|
|
|
namespace Dlhis.Common.SysData.Services.Implements;
|
|
|
|
public class SysDataService : ISysDataService
|
|
{
|
|
private readonly IDbContext _dbContext;
|
|
|
|
public SysDataService(IDbContext dbContext)
|
|
{
|
|
_dbContext = dbContext;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<List<object>> DownloadAsync(string factory, string tableName)
|
|
{
|
|
var type = App.ActiveTypes
|
|
.Where(x => x.IsDefined(typeof(SugarTable), false))
|
|
.Where(x => !x.IsDefined(typeof(SkipScanAttribute), false))
|
|
.FirstOrDefault(x => x.GetCustomAttribute<SugarTable>()!.TableName == tableName);
|
|
|
|
var table = type.GetCustomAttribute<SugarTable>()!.TableName;
|
|
var sql = $"select * from {table}";
|
|
if (type.IsAssignableTo(typeof(ITenantId)))
|
|
{
|
|
sql += $" where tenantId = '{tableName}'";
|
|
}
|
|
|
|
return await _dbContext.Client.SqlQueryable<object>(sql).ToListAsync();
|
|
}
|
|
} |