图层树管理和导出时候字段过滤查询
parent
670da2e3a2
commit
0fc176a678
|
|
@ -1,19 +1,24 @@
|
|||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using Infrastructure;
|
||||
using OpenAuth.App.Base.Tree;
|
||||
using OpenAuth.App.BaseApp.Base;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.ServiceApp.DataMaintenance.Request;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Core;
|
||||
using OpenAuth.Repository.Domain.DataMaintenance;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yitter.IdGenerator;
|
||||
using static NPOI.HSSF.UserModel.HeaderFooter;
|
||||
|
||||
namespace OpenAuth.App.ServiceApp.DataMaintenance
|
||||
{
|
||||
|
|
@ -34,7 +39,7 @@ namespace OpenAuth.App.ServiceApp.DataMaintenance
|
|||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Response<List<ApplicationData>>> GetApplicationList(string name)
|
||||
public async Task<Response<List<ApplicationData>>> GetApplicationList(string name, int isCatalogue)
|
||||
{
|
||||
using (var db = UnitWork.CreateContext())
|
||||
{
|
||||
|
|
@ -68,6 +73,11 @@ namespace OpenAuth.App.ServiceApp.DataMaintenance
|
|||
{
|
||||
baseQuery = baseQuery.Where(a => a.ApplicationName.Contains(name));
|
||||
}
|
||||
//服务过滤
|
||||
if (isCatalogue != 0)
|
||||
{
|
||||
baseQuery = baseQuery.Where(a => a.IsServer == 0);
|
||||
}
|
||||
|
||||
// 执行查询并构建树形结构
|
||||
var query = await baseQuery.Select<ApplicationData>().ToListAsync();
|
||||
|
|
@ -131,5 +141,121 @@ namespace OpenAuth.App.ServiceApp.DataMaintenance
|
|||
};
|
||||
return result;
|
||||
}
|
||||
//获取数据库表名及注释
|
||||
public async Task<Response<DataTable>> GetGeomTableList(PageReq req)
|
||||
{
|
||||
using (var db = UnitWork.CreateContext())
|
||||
{
|
||||
var query = await db.Db.Ado.GetDataTableAsync(@"
|
||||
SELECT t.""table_name"", pg_catalog.obj_description(c.oid) AS table_comment
|
||||
FROM information_schema.tables t JOIN pg_catalog.pg_class c ON c.relname = t.""table_name""
|
||||
WHERE t.table_schema = 'public' AND EXISTS ( SELECT 1
|
||||
FROM information_schema.columns col
|
||||
WHERE col.""table_name"" = t.""table_name""
|
||||
AND col.table_schema = t.table_schema
|
||||
AND col.data_type = 'USER-DEFINED'
|
||||
AND col.udt_name = 'geometry');");
|
||||
|
||||
return new Response<DataTable>()
|
||||
{
|
||||
Result = query,
|
||||
};
|
||||
}
|
||||
}
|
||||
//查询一张表里的所有数据
|
||||
public async Task<Response<PageInfo<List<object>>>> GetDataList(TableDataReq tableDataReq)
|
||||
{
|
||||
using (var db = UnitWork.CreateContext())
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
RefAsync<int> totalNumber = 0;
|
||||
var query = db.Db.Queryable<object>().AS(tableDataReq.TableName);//没实体一样
|
||||
// 构建过滤条件
|
||||
foreach (var filter in tableDataReq.Filter)
|
||||
{
|
||||
// 判断字段类型
|
||||
if (filter.Type == "int")
|
||||
{
|
||||
query.Where(BuildIntCondition(filter.Field, filter.Operator, filter.Value));
|
||||
}
|
||||
else
|
||||
{
|
||||
query.Where(BuildStringCondition(filter.Field, filter.Operator, filter.Value));
|
||||
}
|
||||
}
|
||||
var fields = string.Join(",", tableDataReq.Field.Select(f => $"\"{f}\""));
|
||||
var dataList = await query.Select(fields).ToPageListAsync(tableDataReq.page, tableDataReq.limit, totalNumber);
|
||||
return new Response<PageInfo<List<dynamic>>>
|
||||
{
|
||||
Result = new PageInfo<List<dynamic>> { Items = dataList, Total = totalNumber }
|
||||
};
|
||||
}
|
||||
}
|
||||
//拼接int类型的条件
|
||||
private static string BuildIntCondition(string column, string operators, string value)
|
||||
{
|
||||
if (operators == "大于")
|
||||
{
|
||||
return $"\"{column}\" > {value}";
|
||||
}
|
||||
else if (operators == "小于")
|
||||
{
|
||||
return $"\"{column}\" < {value}";
|
||||
}
|
||||
else if (operators == "大于等于")
|
||||
{
|
||||
return $"\"{column}\" > {value}";
|
||||
}
|
||||
else if (operators == "小于等于")
|
||||
{
|
||||
return $"\"{column}\" > {value}";
|
||||
}
|
||||
else if (operators == "介于")
|
||||
{
|
||||
var range = value.Split(',');
|
||||
if (int.TryParse(range[0], out int lower) && int.TryParse(range[1], out int upper))
|
||||
{
|
||||
return $"\"{column}\" BETWEEN {lower} AND {upper}";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("无效的范围值");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return $"\"{column}\" = {value}";
|
||||
}
|
||||
}
|
||||
//拼接string类型的条件
|
||||
private static string BuildStringCondition(string column, string operators, string value)
|
||||
{
|
||||
if (operators.StartsWith("包含"))
|
||||
{
|
||||
return $"\"{column}\" LIKE '%{value}%'";
|
||||
}
|
||||
else if (operators.StartsWith("不包含"))
|
||||
{
|
||||
return $"\"{column}\" NOT LIKE '%{value}%'";
|
||||
}
|
||||
else if (operators.StartsWith("以开头"))
|
||||
{
|
||||
return $"\"{column}\" LIKE '{value}%'";
|
||||
}
|
||||
else if (operators.StartsWith("以结尾"))
|
||||
{
|
||||
return $"\"{column}\" LIKE '%{value}'";
|
||||
}
|
||||
else
|
||||
{
|
||||
return $"\"{column}\" = '{value}'";
|
||||
}
|
||||
}
|
||||
|
||||
#region 导出数据
|
||||
//导出Excel
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
using OpenAuth.App.BaseApp.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OpenAuth.App.ServiceApp.DataMaintenance.Request
|
||||
{
|
||||
public class TableDataReq : PageReq
|
||||
{
|
||||
//表名
|
||||
public string TableName { get; set; }
|
||||
//过滤条件
|
||||
public List<Filter> Filter { get; set; }
|
||||
//需要查询的字段
|
||||
public List<string> Field { get; set; }
|
||||
}
|
||||
public class Filter
|
||||
{
|
||||
public string Field { get; set; } = string.Empty;
|
||||
public string Value { get; set; } = string.Empty;
|
||||
public string Operator { get; set; } = string.Empty;
|
||||
public string Type { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,12 @@
|
|||
using Infrastructure;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using OpenAuth.App.BaseApp.Base;
|
||||
using OpenAuth.App.ServiceApp.DataMaintenance;
|
||||
using OpenAuth.App.ServiceApp.DataMaintenance.Request;
|
||||
using OpenAuth.Repository.Domain.DataMaintenance;
|
||||
using OpenAuth.WebApi.Model.CustomAttribute;
|
||||
using System.Data;
|
||||
|
||||
namespace OpenAuth.WebApi.Controllers.ServiceControllers.DataMaintenance
|
||||
{
|
||||
|
|
@ -24,11 +27,13 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers.DataMaintenance
|
|||
/// <summary>
|
||||
/// 查询应用列表
|
||||
/// </summary>
|
||||
/// <param name="name">目录或服务名称</param>
|
||||
/// <param name="isCatalogue">是否只查询目录</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Response<List<ApplicationData>>> GetApplicationList(string name)
|
||||
public async Task<Response<List<ApplicationData>>> GetApplicationList(string name, int isCatalogue)
|
||||
{
|
||||
return await _app.GetApplicationList(name);
|
||||
return await _app.GetApplicationList(name, isCatalogue);
|
||||
}
|
||||
/// <summary>
|
||||
/// 添加应用
|
||||
|
|
@ -57,5 +62,36 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers.DataMaintenance
|
|||
{
|
||||
return await _app.Delete(id);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取数据库表名及注释
|
||||
/// </summary>
|
||||
/// <param name="req"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<Response<DataTable>> GetGeomTableList(PageReq req)
|
||||
{
|
||||
return await _app.GetGeomTableList(req);
|
||||
}
|
||||
/// <summary>
|
||||
/// 查询数据
|
||||
/// </summary>
|
||||
/// <param name="tableDataReq"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public async Task<Response<PageInfo<List<object>>>> GetDataList(TableDataReq tableDataReq)
|
||||
{
|
||||
var result = new Response<PageInfo<List<object>>>();
|
||||
try
|
||||
{
|
||||
result = await _app.GetDataList(tableDataReq);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.Code = 500;
|
||||
result.Message = ex.Message;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue