using learun.iapplication;
using learun.util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace EC.Web.Areas.LR_SystemModule.Controllers
{
///
/// 版 本 EasyCode EC管理后台
/// Copyright (c) 2019-present EC管理有限公司
/// 创建人:tobin
/// 日 期:2019.10.23
/// 描 述:数据表管理
///
[Area("LR_SystemModule")]
public class DatabaseTableController : MvcControllerBase
{
private readonly DatabaseTableIBLL _databaseTableIBLL;
private readonly DbDraftIBLL _dbDraftIBLL;
public DatabaseTableController(DatabaseTableIBLL databaseTableIBLL, DbDraftIBLL dbDraftIBLL)
{
_databaseTableIBLL = databaseTableIBLL;
_dbDraftIBLL = dbDraftIBLL;
}
#region 获取视图
///
/// 主页面管理
///
///
[HttpGet]
public IActionResult Index()
{
return View();
}
///
/// 表数据查询
///
///
[HttpGet]
public IActionResult TableIndex()
{
return View();
}
///
/// 新增、编辑表页面
///
///
[HttpGet]
public IActionResult EditTableForm()
{
return View();
}
///
/// 复制表
///
///
[HttpGet]
public IActionResult CopyTableForm()
{
return View();
}
///
/// 草稿管理
///
///
[HttpGet]
public IActionResult DraftForm()
{
return View();
}
#endregion 获取视图
#region 获取数据
///
/// 获取数据表数据
///
/// 连接串编码
/// 表名
///
[HttpGet]
[AjaxOnly]
public async Task GetList(string dbCode, string tableName)
{
var data = await _databaseTableIBLL.GetTableList(dbCode, tableName);
return Success(data);
}
///
/// 获取表的字段数据
///
/// 连接串编码
/// 表名
///
[HttpGet]
[AjaxOnly]
public async Task GetFieldList(string dbCode, string tableName)
{
var data = await _databaseTableIBLL.GetTableFiledList(dbCode, tableName);
return Success(data);
}
///
/// 获取表数据
///
/// 连接串编码
/// 表名
/// 字段名
/// 逻辑
/// 关键字
/// 分页参数
///
[HttpGet]
[AjaxOnly]
public async Task GetTableDataList(string dbCode, string tableName, string field, string logic, string keyword, string pagination)
{
Pagination paginationobj = pagination.ToObject();
var data = await _databaseTableIBLL.GetTableDataList(dbCode, tableName, field, logic, keyword, paginationobj);
var jsonData = new
{
rows = data,
paginationobj.total,
paginationobj.page,
paginationobj.records,
};
return Success(jsonData);
}
///
/// 获取表数据
///
/// 连接串编码
/// 表名
///
[HttpGet]
[AjaxOnly]
public async Task GetTableDataAllList(string dbCode, string tableName)
{
var data = await _databaseTableIBLL.GetTableDataList(dbCode, tableName);
return Success(data);
}
///
/// 获取表数据(树形数据)
///
/// 连接串主键
///
[HttpGet]
[AjaxOnly]
public async Task GetTreeList(string parentId)
{
var data = await _databaseTableIBLL.GetTreeList(parentId);
return Success(data);
}
///
/// 获取表字段树形数据
///
/// 连接串编码
/// 表名
///
public async Task GetFieldTreeList(string dbCode, string tableName)
{
var data = await _databaseTableIBLL.GetFiledTreeList(dbCode, tableName);
return Success(data);
}
///
/// 给定查询语句查询字段
///
/// 连接串编码
/// sql语句
///
public async Task GetSqlColName(string dbCode, string strSql)
{
var data = await _databaseTableIBLL.GetSqlColName(dbCode, strSql);
return Success(data);
}
///
/// 获取建表草稿
///
/// 查询参数
///
[HttpGet]
[AjaxOnly]
public async Task GetDraftList(string queryJson)
{
var data = await _dbDraftIBLL.GetList(queryJson);
return Success(data);
}
#endregion 获取数据
#region 提交数据
///
/// 保存列数据(新增、修改)
///
/// 主键
/// 实体
///
[HttpPost]
[AjaxOnly]
public async Task SaveDraft(string keyValue, DbDraftEntity entity)
{
await _dbDraftIBLL.SaveEntity(keyValue, entity);
return Success("保存草稿成功", entity.F_Id);
}
///
/// 保存列数据(新增、修改)
///
/// 主键
///
[HttpPost]
[AjaxOnly]
public async Task DeleteDraft(string keyValue)
{
await _dbDraftIBLL.DeleteEntity(keyValue);
return SuccessInfo("删除草稿成功");
}
///
/// 建表
///
/// 数据库连接编码
/// 草稿ID
/// 表名
/// 备注
/// 字段列表
///
[HttpPost]
[AjaxOnly]
public async Task SaveTable(string dbCode, string draftId, string tableName, string tableRemark, string strColList)
{
List colList = strColList.ToObject>();
string res = await _databaseTableIBLL.CreateTable(dbCode, tableName, tableRemark, colList);
if (res == "建表成功")
{
if (!string.IsNullOrEmpty(draftId))
{
await _dbDraftIBLL.DeleteEntity(draftId);
}
return SuccessInfo("创建成功");
}
else
{
return Fail(res);
}
}
#endregion 提交数据
#region 扩展方法
///
/// 判断数据表字段重复
///
/// 主键值
/// 表名
/// 主键名
/// 数据字段
///
[HttpGet]
[AjaxOnly]
public async Task ExistFiled(string keyValue, string tableName, string keyName, string filedsJson)
{
var res = await _databaseTableIBLL.ExistFiled(keyValue, tableName, keyName, filedsJson);
return Success(res);
}
#endregion 扩展方法
}
}