feat 提供数据下载功能
This commit is contained in:
24
Src/Dlhis.Common/SysData/Controller/SysDataController.cs
Normal file
24
Src/Dlhis.Common/SysData/Controller/SysDataController.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Dlhis.Common.SysData.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Dlhis.Common.SysData.Controller;
|
||||
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class SysDataController : ControllerBase
|
||||
{
|
||||
private readonly ISysDataService _sysDataService;
|
||||
|
||||
public SysDataController(ISysDataService sysDataService)
|
||||
{
|
||||
_sysDataService = sysDataService;
|
||||
}
|
||||
|
||||
[HttpGet("download")]
|
||||
public async Task<List<object>> DownloadAsync(string factory, string tableName)
|
||||
{
|
||||
return await _sysDataService.DownloadAsync(factory, tableName);
|
||||
}
|
||||
}
|
||||
6
Src/Dlhis.Common/SysData/Services/ISysDataService.cs
Normal file
6
Src/Dlhis.Common/SysData/Services/ISysDataService.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Dlhis.Common.SysData.Services;
|
||||
|
||||
public interface ISysDataService : IScopeDependency
|
||||
{
|
||||
Task<List<object>> DownloadAsync(string factory, string tableName);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user