// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
namespace Admin.NET.Core.Service;
using AspectCore.Extensions.Reflection;
using NewLife.Data;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Schema;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using SqlSugar;
using StackExchange.Redis;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text.RegularExpressions;
///
///
///
public class SelectTable : ISingleton
{
private readonly IdentityService _identitySvc;
private readonly TableMapper _tableMapper;
private readonly ISqlSugarClient _db;
///
///
///
///
///
///
public SelectTable(IdentityService identityService, TableMapper tableMapper, ISqlSugarClient dbClient)
{
_identitySvc = identityService;
_tableMapper = tableMapper;
_db = dbClient;
}
///
/// 判断表名是否正确,如果不正确则抛异常
///
///
///
public virtual bool IsTable(string table)
{
if (_db.DbMaintenance.GetTableInfoList().Any(it => it.Name.Equals(table, StringComparison.CurrentCultureIgnoreCase)))
return true;
else
throw new Exception($"表名【{table}】不正确!");
}
///
/// 判断表的列名是否正确,如果不正确则抛异常,更早地暴露给调用方
///
///
///
///
public virtual bool IsCol(string table, string col)
{
if (_db.DbMaintenance.GetColumnInfosByTableName(table).Any(it => it.DbColumnName.Equals(col, StringComparison.CurrentCultureIgnoreCase)))
return true;
else
throw new Exception($"表【{table}】不存在列【{col}】!请检查输入参数");
}
///
///
///
///
///
///
///
///
///
public virtual Tuple GetTableData(string subtable, int page, int count, int query, string json, JObject dd)
{
var role = _identitySvc.GetSelectRole(subtable);
if (!role.Item1)//没有权限返回异常
{
throw new Exception(role.Item2);
}
string selectrole = role.Item2;
subtable = _tableMapper.GetTableName(subtable);
JObject values = JObject.Parse(json);
page = values["page"] == null ? page : int.Parse(values["page"].ToString());
count = values["count"] == null ? count : int.Parse(values["count"].ToString());
query = values["query"] == null ? query : int.Parse(values["query"].ToString());
values.Remove("page");
values.Remove("count");
var tb = SugarQueryable(subtable, selectrole, values, dd);
if (query == 1)//1-总数
return new Tuple(new List