mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-04-05 17:38:01 +08:00
增加外部数据源管理
This commit is contained in:
parent
be1c79799d
commit
4dd882cf90
77
OpenAuth.App/ExtDataSourceApp/ExtDataSourceApp.cs
Normal file
77
OpenAuth.App/ExtDataSourceApp/ExtDataSourceApp.cs
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Infrastructure;
|
||||||
|
using OpenAuth.App.Interface;
|
||||||
|
using OpenAuth.App.Request;
|
||||||
|
using OpenAuth.App.Response;
|
||||||
|
using OpenAuth.Repository.Domain;
|
||||||
|
using SqlSugar;
|
||||||
|
|
||||||
|
|
||||||
|
namespace OpenAuth.App
|
||||||
|
{
|
||||||
|
public class ExtDataSourceApp : SqlSugarBaseApp<ExternalDataSource>
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 加载列表
|
||||||
|
/// </summary>
|
||||||
|
public async Task<TableData> Load(QueryExternalDataSourceListReq request)
|
||||||
|
{
|
||||||
|
var loginContext = _auth.GetCurrentUser();
|
||||||
|
if (loginContext == null)
|
||||||
|
{
|
||||||
|
throw new CommonException("登录已过期", Define.INVALID_TOKEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = new TableData();
|
||||||
|
var objs = GetDataPrivilege("u");
|
||||||
|
if (!string.IsNullOrEmpty(request.key))
|
||||||
|
{
|
||||||
|
objs = objs.Where(u => u.Name.Contains(request.key));
|
||||||
|
}
|
||||||
|
|
||||||
|
result.data = objs.OrderBy(u => u.Name)
|
||||||
|
.Skip((request.page - 1) * request.limit)
|
||||||
|
.Take(request.limit).ToList();
|
||||||
|
result.count = await objs.CountAsync();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Add(AddOrUpdateExternalDataSourceReq req)
|
||||||
|
{
|
||||||
|
var obj = req.MapTo<ExternalDataSource>();
|
||||||
|
obj.Createtime = DateTime.Now;
|
||||||
|
var user = _auth.GetCurrentUser().User;
|
||||||
|
obj.Createuserid = user.Id;
|
||||||
|
obj.Createusername = user.Name;
|
||||||
|
Repository.Insert(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(AddOrUpdateExternalDataSourceReq obj)
|
||||||
|
{
|
||||||
|
var user = _auth.GetCurrentUser().User;
|
||||||
|
Repository.Update(u => new ExternalDataSource
|
||||||
|
{
|
||||||
|
Dbtype = obj.Dbtype,
|
||||||
|
Databasename = obj.Databasename,
|
||||||
|
Server = obj.Server,
|
||||||
|
Port = obj.Port,
|
||||||
|
Username = obj.Username,
|
||||||
|
Password = obj.Password,
|
||||||
|
Description = obj.Description,
|
||||||
|
Enabled = obj.Enabled,
|
||||||
|
Testsuccess = obj.Testsuccess,
|
||||||
|
Connectionstring = obj.Connectionstring,
|
||||||
|
Updatetime = DateTime.Now,
|
||||||
|
Updateuserid = user.Id,
|
||||||
|
Updateusername = user.Name
|
||||||
|
},u => u.Id == obj.Id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExtDataSourceApp(ISqlSugarClient client, IAuth auth) : base(client, auth)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,113 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// This code was generated by a CodeSmith Template.
|
||||||
|
//
|
||||||
|
// DO NOT MODIFY contents of this file. Changes to this
|
||||||
|
// file will be lost if the code is regenerated.
|
||||||
|
// Author:Yubao Li
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using OpenAuth.Repository.Core;
|
||||||
|
|
||||||
|
namespace OpenAuth.App.Request
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
|
||||||
|
public class AddOrUpdateExternalDataSourceReq
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///创建时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime Createtime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///创建用户名
|
||||||
|
/// </summary>
|
||||||
|
public string Createusername { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///创建用户ID
|
||||||
|
/// </summary>
|
||||||
|
public string Createuserid { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///更新用户ID
|
||||||
|
/// </summary>
|
||||||
|
public string Updateuserid { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///更新用户名
|
||||||
|
/// </summary>
|
||||||
|
public string Updateusername { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///是否测试成功
|
||||||
|
/// </summary>
|
||||||
|
public bool? Testsuccess { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///最后测试时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? Updatetime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///主键
|
||||||
|
/// </summary>
|
||||||
|
public string Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///是否启用
|
||||||
|
/// </summary>
|
||||||
|
public bool Enabled { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///连接字符串
|
||||||
|
/// </summary>
|
||||||
|
public string Connectionstring { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///描述
|
||||||
|
/// </summary>
|
||||||
|
public string Description { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///密码
|
||||||
|
/// </summary>
|
||||||
|
public string Password { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///用户名
|
||||||
|
/// </summary>
|
||||||
|
public string Username { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///端口
|
||||||
|
/// </summary>
|
||||||
|
public int? Port { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///服务器地址
|
||||||
|
/// </summary>
|
||||||
|
public string Server { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///数据库名称
|
||||||
|
/// </summary>
|
||||||
|
public string Databasename { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///数据库类型
|
||||||
|
/// </summary>
|
||||||
|
public string Dbtype { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///数据源名称
|
||||||
|
/// </summary>
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
namespace OpenAuth.App.Request
|
||||||
|
{
|
||||||
|
public class QueryExternalDataSourceListReq : PageReq
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
139
OpenAuth.Repository/Domain/ExternalDataSource.cs
Normal file
139
OpenAuth.Repository/Domain/ExternalDataSource.cs
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using OpenAuth.Repository.Core;
|
||||||
|
|
||||||
|
namespace OpenAuth.Repository.Domain
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///外部数据源
|
||||||
|
/// </summary>
|
||||||
|
[Table("ExternalDataSource")]
|
||||||
|
public class ExternalDataSource : StringEntity
|
||||||
|
{
|
||||||
|
public ExternalDataSource()
|
||||||
|
{
|
||||||
|
this.Createtime = DateTime.Now;
|
||||||
|
this.Createusername = "";
|
||||||
|
this.Createuserid = "";
|
||||||
|
this.Updateuserid = "";
|
||||||
|
this.Updateusername = "";
|
||||||
|
this.Testsuccess = false;
|
||||||
|
this.Updatetime = DateTime.Now;
|
||||||
|
this.Enabled = false;
|
||||||
|
this.Connectionstring = "";
|
||||||
|
this.Description = "";
|
||||||
|
this.Password = "";
|
||||||
|
this.Username = "";
|
||||||
|
this.Port = 0;
|
||||||
|
this.Server = "";
|
||||||
|
this.Databasename = "";
|
||||||
|
this.Dbtype = "";
|
||||||
|
this.Name = "";
|
||||||
|
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
///创建时间
|
||||||
|
/// </summary>
|
||||||
|
[Description("创建时间")]
|
||||||
|
public DateTime Createtime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///创建用户名
|
||||||
|
/// </summary>
|
||||||
|
[Description("创建用户名")]
|
||||||
|
public string Createusername { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///创建用户ID
|
||||||
|
/// </summary>
|
||||||
|
[Description("创建用户ID")]
|
||||||
|
public string Createuserid { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///更新用户ID
|
||||||
|
/// </summary>
|
||||||
|
[Description("更新用户ID")]
|
||||||
|
public string Updateuserid { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///更新用户名
|
||||||
|
/// </summary>
|
||||||
|
[Description("更新用户名")]
|
||||||
|
public string Updateusername { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///是否测试成功
|
||||||
|
/// </summary>
|
||||||
|
[Description("是否测试成功")]
|
||||||
|
public bool? Testsuccess { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///最后测试时间
|
||||||
|
/// </summary>
|
||||||
|
[Description("最后测试时间")]
|
||||||
|
public DateTime? Updatetime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///是否启用
|
||||||
|
/// </summary>
|
||||||
|
[Description("是否启用")]
|
||||||
|
public bool Enabled { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///连接字符串
|
||||||
|
/// </summary>
|
||||||
|
[Description("连接字符串")]
|
||||||
|
public string Connectionstring { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///描述
|
||||||
|
/// </summary>
|
||||||
|
[Description("描述")]
|
||||||
|
public string Description { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///密码
|
||||||
|
/// </summary>
|
||||||
|
[Description("密码")]
|
||||||
|
public string Password { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///用户名
|
||||||
|
/// </summary>
|
||||||
|
[Description("用户名")]
|
||||||
|
public string Username { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///端口
|
||||||
|
/// </summary>
|
||||||
|
[Description("端口")]
|
||||||
|
public int? Port { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///服务器地址
|
||||||
|
/// </summary>
|
||||||
|
[Description("服务器地址")]
|
||||||
|
public string Server { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///数据库名称
|
||||||
|
/// </summary>
|
||||||
|
[Description("数据库名称")]
|
||||||
|
public string Databasename { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///数据库类型
|
||||||
|
/// </summary>
|
||||||
|
[Description("数据库类型")]
|
||||||
|
public string Dbtype { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///数据源名称
|
||||||
|
/// </summary>
|
||||||
|
[Description("数据源名称")]
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
113
OpenAuth.WebApi/Controllers/ExternalDataSourcesController.cs
Normal file
113
OpenAuth.WebApi/Controllers/ExternalDataSourcesController.cs
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Infrastructure;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using OpenAuth.App;
|
||||||
|
using OpenAuth.App.Request;
|
||||||
|
using OpenAuth.App.Response;
|
||||||
|
using OpenAuth.Repository.Domain;
|
||||||
|
|
||||||
|
namespace OpenAuth.WebApi.Controllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 外部数据源管理接口
|
||||||
|
/// </summary>
|
||||||
|
[Route("api/[controller]/[action]")]
|
||||||
|
[ApiController]
|
||||||
|
[ApiExplorerSettings(GroupName = "外部数据源管理接口_ExternalDataSources")]
|
||||||
|
public class ExternalDataSourcesController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly ExtDataSourceApp _app;
|
||||||
|
|
||||||
|
//获取详情
|
||||||
|
[HttpGet]
|
||||||
|
public Response<ExternalDataSource> Get(string id)
|
||||||
|
{
|
||||||
|
var result = new Response<ExternalDataSource>();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result.Result = _app.Get(id);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
result.Code = 500;
|
||||||
|
result.Message = ex.InnerException?.Message ?? ex.Message;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//添加
|
||||||
|
[HttpPost]
|
||||||
|
public Response Add([FromBody]AddOrUpdateExternalDataSourceReq obj)
|
||||||
|
{
|
||||||
|
var result = new Response();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_app.Add(obj);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
result.Code = 500;
|
||||||
|
result.Message = ex.InnerException?.Message ?? ex.Message;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//修改
|
||||||
|
[HttpPost]
|
||||||
|
public Response Update([FromBody]AddOrUpdateExternalDataSourceReq obj)
|
||||||
|
{
|
||||||
|
var result = new Response();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_app.Update(obj);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
result.Code = 500;
|
||||||
|
result.Message = ex.InnerException?.Message ?? ex.Message;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 加载列表
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<TableData> Load([FromQuery]QueryExternalDataSourceListReq request)
|
||||||
|
{
|
||||||
|
return await _app.Load(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 批量删除
|
||||||
|
/// </summary>
|
||||||
|
[HttpPost]
|
||||||
|
public Response Delete([FromBody]string[] ids)
|
||||||
|
{
|
||||||
|
var result = new Response();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_app.Delete(ids);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
result.Code = 500;
|
||||||
|
result.Message = ex.InnerException?.Message ?? ex.Message;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExternalDataSourcesController(ExtDataSourceApp app)
|
||||||
|
{
|
||||||
|
_app = app;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user