mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2026-06-23 00:52:07 +08:00
🔄refactor: 调整为SqlSugar
This commit is contained in:
@@ -11,7 +11,6 @@ using Infrastructure;
|
||||
using Infrastructure.Extensions;
|
||||
using Infrastructure.Helpers;
|
||||
using Infrastructure.Utilities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyModel;
|
||||
using Microsoft.Extensions.Options;
|
||||
using OpenAuth.App.Interface;
|
||||
@@ -20,12 +19,12 @@ using OpenAuth.App.Response;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Core;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
using SqlSugar;
|
||||
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class BuilderTableApp : BaseStringApp<BuilderTable, OpenAuthDBContext>
|
||||
public class BuilderTableApp : SqlSugarBaseApp<BuilderTable>
|
||||
{
|
||||
private BuilderTableColumnApp _builderTableColumnApp;
|
||||
private CategoryApp _categoryApp;
|
||||
@@ -34,9 +33,9 @@ namespace OpenAuth.App
|
||||
private string _startName = "";
|
||||
private IOptions<AppSetting> _appConfiguration;
|
||||
|
||||
public BuilderTableApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<BuilderTable, OpenAuthDBContext> repository,
|
||||
public BuilderTableApp(ISqlSugarClient client,
|
||||
RevelanceManagerApp app, IAuth auth, DbExtension dbExtension, BuilderTableColumnApp builderTableColumnApp,
|
||||
IOptions<AppSetting> appConfiguration, CategoryApp categoryApp) : base(unitWork, repository, auth)
|
||||
IOptions<AppSetting> appConfiguration, CategoryApp categoryApp) : base(client, auth)
|
||||
{
|
||||
_dbExtension = dbExtension;
|
||||
_builderTableColumnApp = builderTableColumnApp;
|
||||
@@ -87,7 +86,7 @@ namespace OpenAuth.App
|
||||
}
|
||||
|
||||
var result = new PagedListDataResp<BuilderTable>();
|
||||
var objs = UnitWork.Find<BuilderTable>(null);
|
||||
var objs = SugarClient.Queryable<BuilderTable>();
|
||||
if (!string.IsNullOrEmpty(request.key))
|
||||
{
|
||||
objs = objs.Where(u => u.Id.Contains(request.key));
|
||||
@@ -126,7 +125,6 @@ namespace OpenAuth.App
|
||||
Check(req);
|
||||
var obj = AddTableAndColumns(req.MapTo<BuilderTable>());
|
||||
|
||||
UnitWork.Save();
|
||||
return obj.Id;
|
||||
}
|
||||
|
||||
@@ -143,8 +141,7 @@ namespace OpenAuth.App
|
||||
var user = _auth.GetCurrentUser().User;
|
||||
obj.CreateUserId = user.Id;
|
||||
obj.CreateUserName = user.Name;
|
||||
UnitWork.Add(obj);
|
||||
UnitWork.Save(); //需要先保存表结构,后面才能正常判定
|
||||
Repository.Insert(obj);
|
||||
|
||||
_dbExtension.ProcessExternalDb(obj.Id); //先处理外部数据库连接
|
||||
var columns = _dbExtension.GetDbTableStructure(obj.TableName);
|
||||
@@ -175,7 +172,7 @@ namespace OpenAuth.App
|
||||
CreateUserName = user.Name,
|
||||
CreateTime = DateTime.Now
|
||||
};
|
||||
UnitWork.Add(builderColumn);
|
||||
SugarClient.Insertable(builderColumn).ExecuteCommand();
|
||||
}
|
||||
|
||||
return obj;
|
||||
@@ -185,7 +182,7 @@ namespace OpenAuth.App
|
||||
{
|
||||
Check(obj);
|
||||
var user = _auth.GetCurrentUser().User;
|
||||
UnitWork.Update<BuilderTable>(u => u.Id == obj.Id, u => new BuilderTable
|
||||
Repository.Update(u => new BuilderTable
|
||||
{
|
||||
TableName = obj.TableName,
|
||||
Remark = obj.Remark,
|
||||
@@ -204,7 +201,7 @@ namespace OpenAuth.App
|
||||
UpdateUserId = user.Id,
|
||||
UpdateUserName = user.Name,
|
||||
ExternalDataSourceId = obj.ExternalDataSourceId //外部数据源ID
|
||||
});
|
||||
}, u => u.Id == obj.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -213,12 +210,10 @@ namespace OpenAuth.App
|
||||
/// <param name="ids"></param>
|
||||
public void DelTableAndcolumns(string[] ids)
|
||||
{
|
||||
UnitWork.ExecuteWithTransaction(() =>
|
||||
{
|
||||
UnitWork.Delete<BuilderTable>(u => ids.Contains(u.Id));
|
||||
UnitWork.Delete<BuilderTableColumn>(u => ids.Contains(u.TableId));
|
||||
UnitWork.Save();
|
||||
});
|
||||
SugarClient.Ado.BeginTran();
|
||||
SugarClient.Deleteable<BuilderTable>().Where(u => ids.Contains(u.Id)).ExecuteCommand();
|
||||
SugarClient.Deleteable<BuilderTableColumn>().Where(u => ids.Contains(u.TableId)).ExecuteCommand();
|
||||
SugarClient.Ado.CommitTran();
|
||||
}
|
||||
|
||||
|
||||
@@ -228,7 +223,7 @@ namespace OpenAuth.App
|
||||
/// <returns></returns>
|
||||
public void CreateEntity(CreateEntityReq req)
|
||||
{
|
||||
var sysTableInfo = Repository.FirstOrDefault(u => u.Id == req.Id);
|
||||
var sysTableInfo = SugarClient.Queryable<BuilderTable>().First(u => u.Id == req.Id);
|
||||
var tableColumns = _builderTableColumnApp.Find(req.Id);
|
||||
if (sysTableInfo == null
|
||||
|| tableColumns == null
|
||||
@@ -247,7 +242,7 @@ namespace OpenAuth.App
|
||||
/// <returns></returns>
|
||||
public void CreateBusiness(CreateBusiReq req)
|
||||
{
|
||||
var sysTableInfo = Repository.FirstOrDefault(u => u.Id == req.Id);
|
||||
var sysTableInfo = SugarClient.Queryable<BuilderTable>().First(u => u.Id == req.Id);
|
||||
var mainColumns = _builderTableColumnApp.Find(req.Id);
|
||||
if (sysTableInfo == null
|
||||
|| mainColumns == null
|
||||
@@ -319,7 +314,7 @@ namespace OpenAuth.App
|
||||
|
||||
string domainContent = string.Empty;
|
||||
//查找是否存在子表的情况
|
||||
var subTable = Repository.FirstOrDefault(u => u.ParentTableId == sysTableInfo.Id);
|
||||
var subTable = SugarClient.Queryable<BuilderTable>().First(u => u.ParentTableId == sysTableInfo.Id);
|
||||
|
||||
if (subTable == null) //如果子表不存在,则用单模版生成
|
||||
{
|
||||
@@ -386,21 +381,7 @@ namespace OpenAuth.App
|
||||
{
|
||||
throw new Exception($"未能找到表{sysTableInfo.TableName}的主键字段");
|
||||
}
|
||||
if (primarykey.ColumnType == "decimal" || primarykey.ColumnType == "numeric") //是否为数字
|
||||
{
|
||||
if (primarykey.IsIncrement) //是否自增
|
||||
{
|
||||
domainContent = domainContent.Replace("{BaseAppName}", "BaseIntAutoGenApp");
|
||||
}
|
||||
else //普通的雪花算法生成id
|
||||
{
|
||||
domainContent = domainContent.Replace("{BaseAppName}", "BaseLongApp");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
domainContent = domainContent.Replace("{BaseAppName}", "BaseStringApp");
|
||||
}
|
||||
domainContent = domainContent.Replace("{BaseAppName}", "SqlSugarBaseApp");
|
||||
FileHelper.WriteFile($"{appRootPath}\\{sysTableInfo.ModuleCode}", $"{sysTableInfo.ModuleCode}.cs", domainContent);
|
||||
}
|
||||
|
||||
@@ -465,7 +446,7 @@ namespace OpenAuth.App
|
||||
}
|
||||
|
||||
//查找是否存在子表的情况
|
||||
var subTable = Repository.FirstOrDefault(u => u.ParentTableId == sysTableInfo.Id);
|
||||
var subTable = SugarClient.Queryable<BuilderTable>().First(u => u.ParentTableId == sysTableInfo.Id);
|
||||
|
||||
if (subTable != null) //如果子表存在,需要加子表的请求参数
|
||||
{
|
||||
@@ -705,7 +686,7 @@ namespace OpenAuth.App
|
||||
{
|
||||
var types = AssemblyLoadContext.Default
|
||||
.LoadFromAssemblyName(new AssemblyName(compilation.Name))
|
||||
.GetTypes().Where(x => x.GetTypeInfo().BaseType != null
|
||||
.GetTypes().Where(x => System.Reflection.IntrospectionExtensions.GetTypeInfo(x).BaseType != null
|
||||
&& x.BaseType == typeof(StringEntity));
|
||||
foreach (var entity in types)
|
||||
{
|
||||
@@ -736,7 +717,7 @@ namespace OpenAuth.App
|
||||
{
|
||||
throw new Exception("请提供vue项目的根目录,如:C:\\OpenAuth.Pro\\Client");
|
||||
}
|
||||
var sysTableInfo = Repository.FirstOrDefault(u => u.Id == req.Id);
|
||||
var sysTableInfo = SugarClient.Queryable<BuilderTable>().First(u => u.Id == req.Id);
|
||||
|
||||
if (!string.IsNullOrEmpty(sysTableInfo.ParentTableId))
|
||||
{
|
||||
@@ -753,7 +734,7 @@ namespace OpenAuth.App
|
||||
string domainContent = string.Empty;
|
||||
|
||||
//查找是否存在子表额情况
|
||||
var subTable = Repository.FirstOrDefault(u => u.ParentTableId == req.Id);
|
||||
var subTable = SugarClient.Queryable<BuilderTable>().First(u => u.ParentTableId == req.Id);
|
||||
|
||||
if (subTable == null) //如果子表不存在,则用单模版生成
|
||||
{
|
||||
@@ -868,7 +849,7 @@ namespace OpenAuth.App
|
||||
{
|
||||
throw new Exception("请提供vue项目的根目录,如:C:\\OpenAuth.Pro\\Client");
|
||||
}
|
||||
var sysTableInfo = Repository.FirstOrDefault(u => u.Id == req.Id);
|
||||
var sysTableInfo = SugarClient.Queryable<BuilderTable>().First(u => u.Id == req.Id);
|
||||
var tableColumns = _builderTableColumnApp.Find(req.Id);
|
||||
if (sysTableInfo == null
|
||||
|| tableColumns == null
|
||||
@@ -890,7 +871,7 @@ namespace OpenAuth.App
|
||||
public async Task<PagedDynamicDataResp> AllMain()
|
||||
{
|
||||
var result = new PagedDynamicDataResp();
|
||||
var objs = UnitWork.Find<BuilderTable>(u => string.IsNullOrEmpty(u.ParentTableId)).Select(u => new
|
||||
var objs = SugarClient.Queryable<BuilderTable>().Where(u => string.IsNullOrEmpty(u.ParentTableId)).Select(u => new
|
||||
{
|
||||
Id = u.Id,
|
||||
Name = u.TableName
|
||||
|
||||
@@ -3,18 +3,16 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.Response;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
using SqlSugar;
|
||||
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class CategoryTypeApp : BaseStringApp<CategoryType,OpenAuthDBContext>
|
||||
public class CategoryTypeApp : SqlSugarBaseApp<CategoryType>
|
||||
{
|
||||
private RevelanceManagerApp _revelanceApp;
|
||||
|
||||
@@ -24,7 +22,7 @@ namespace OpenAuth.App
|
||||
public async Task<PagedDynamicDataResp> Load(QueryCategoryTypeListReq request)
|
||||
{
|
||||
var result = new PagedDynamicDataResp();
|
||||
var objs = UnitWork.Find<CategoryType>(null);
|
||||
var objs = SugarClient.Queryable<CategoryType>();
|
||||
if (!string.IsNullOrEmpty(request.key))
|
||||
{
|
||||
objs = objs.Where(u => u.Id.Contains(request.key) || u.Name.Contains(request.key));
|
||||
@@ -42,39 +40,37 @@ namespace OpenAuth.App
|
||||
var obj = req.MapTo<CategoryType>();
|
||||
//todo:补充或调整自己需要的字段
|
||||
obj.CreateTime = DateTime.Now;
|
||||
Repository.Add(obj);
|
||||
Repository.Insert(obj);
|
||||
}
|
||||
|
||||
public void Update(AddOrUpdateCategoryTypeReq obj)
|
||||
{
|
||||
var user = _auth.GetCurrentUser().User;
|
||||
UnitWork.Update<CategoryType>(u => u.Id == obj.Id, u => new CategoryType
|
||||
Repository.Update(u => new CategoryType
|
||||
{
|
||||
Name = obj.Name,
|
||||
CreateTime = DateTime.Now
|
||||
//todo:补充或调整自己需要的字段
|
||||
});
|
||||
}, u => u.Id == obj.Id);
|
||||
|
||||
}
|
||||
|
||||
public new void Delete(string[] ids)
|
||||
{
|
||||
UnitWork.ExecuteWithTransaction(() =>
|
||||
{
|
||||
UnitWork.Delete<CategoryType>(u=>ids.Contains(u.Id));
|
||||
UnitWork.Delete<Category>(u=>ids.Contains(u.TypeId));
|
||||
UnitWork.Save();
|
||||
});
|
||||
SugarClient.Ado.BeginTran();
|
||||
SugarClient.Deleteable<CategoryType>().Where(u=>ids.Contains(u.Id)).ExecuteCommand();
|
||||
SugarClient.Deleteable<Category>().Where(u=>ids.Contains(u.TypeId)).ExecuteCommand();
|
||||
SugarClient.Ado.CommitTran();
|
||||
|
||||
}
|
||||
|
||||
public List<CategoryType> AllTypes()
|
||||
{
|
||||
return UnitWork.Find<CategoryType>(null).ToList();
|
||||
return SugarClient.Queryable<CategoryType>().ToList();
|
||||
}
|
||||
|
||||
public CategoryTypeApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<CategoryType,OpenAuthDBContext> repository,
|
||||
RevelanceManagerApp app, IAuth auth) : base(unitWork, repository,auth)
|
||||
public CategoryTypeApp(ISqlSugarClient client,
|
||||
RevelanceManagerApp app, IAuth auth) : base(client, auth)
|
||||
{
|
||||
_revelanceApp = app;
|
||||
}
|
||||
|
||||
@@ -7,31 +7,29 @@ using Infrastructure;
|
||||
using Infrastructure.Extensions;
|
||||
using Infrastructure.Helpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.Response;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
using SqlSugar;
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件管理
|
||||
/// </summary>
|
||||
public class FileApp : BaseStringApp<UploadFile,OpenAuthDBContext>
|
||||
public class FileApp : SqlSugarBaseApp<UploadFile>
|
||||
{
|
||||
private ILogger<FileApp> _logger;
|
||||
private string _filePath;
|
||||
private string _dbFilePath; //数据库中的文件路径
|
||||
private string _dbThumbnail; //数据库中的缩略图路径
|
||||
|
||||
public FileApp(IOptions<AppSetting> setOptions, IUnitWork<OpenAuthDBContext> unitWork, IRepository<UploadFile,OpenAuthDBContext> repository,
|
||||
public FileApp(IOptions<AppSetting> setOptions, ISqlSugarClient client,
|
||||
ILogger<FileApp> logger, IAuth auth)
|
||||
: base(unitWork, repository, auth)
|
||||
: base(client, auth)
|
||||
{
|
||||
_logger = logger;
|
||||
_filePath = setOptions.Value.UploadPath;
|
||||
@@ -47,7 +45,7 @@ namespace OpenAuth.App
|
||||
public async Task<PagedDynamicDataResp> Load(QueryFileListReq request)
|
||||
{
|
||||
var result = new PagedDynamicDataResp();
|
||||
var objs = UnitWork.Find<UploadFile>(null);
|
||||
var objs = SugarClient.Queryable<UploadFile>();
|
||||
if (!string.IsNullOrEmpty(request.key))
|
||||
{
|
||||
objs = objs.Where(u => u.FileName.Contains(request.key) || u.FilePath.Contains(request.key));
|
||||
@@ -112,7 +110,7 @@ namespace OpenAuth.App
|
||||
FileType = Path.GetExtension(fileName),
|
||||
Extension = Path.GetExtension(fileName)
|
||||
};
|
||||
Repository.Add(filedb);
|
||||
Repository.Insert(filedb);
|
||||
return filedb;
|
||||
}
|
||||
}
|
||||
@@ -126,9 +124,9 @@ namespace OpenAuth.App
|
||||
/// 删除附件
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
public override void Delete(string[] ids)
|
||||
public new void Delete(string[] ids)
|
||||
{
|
||||
var files = base.Repository.Find(u => ids.Contains(u.Id)).ToList();
|
||||
var files = SugarClient.Queryable<UploadFile>().Where(u => ids.Contains(u.Id)).ToList();
|
||||
for (int i = 0; i < files.Count(); i++)
|
||||
{
|
||||
var uploadPath = Path.Combine(_filePath, files[i].FilePath);
|
||||
@@ -137,7 +135,7 @@ namespace OpenAuth.App
|
||||
{
|
||||
FileHelper.FileDel(Path.Combine(_filePath, files[i].Thumbnail));
|
||||
}
|
||||
Repository.Delete(u =>u.Id == files[i].Id);
|
||||
SugarClient.Deleteable<UploadFile>().Where(u =>u.Id == files[i].Id).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,8 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using Infrastructure;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Interface;
|
||||
using OpenAuth.Repository.QueryObj;
|
||||
using SqlSugar;
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
/// <summary>
|
||||
@@ -13,10 +12,10 @@ namespace OpenAuth.App
|
||||
/// </summary>
|
||||
public class DragForm: IForm
|
||||
{
|
||||
private IUnitWork<OpenAuthDBContext> _unitWork;
|
||||
public DragForm(IUnitWork<OpenAuthDBContext> unitWork)
|
||||
private ISqlSugarClient _sugarClient;
|
||||
public DragForm(ISqlSugarClient sugarClient)
|
||||
{
|
||||
_unitWork = unitWork;
|
||||
_sugarClient = sugarClient;
|
||||
}
|
||||
/**
|
||||
* 功能: 创建表单数据表格(基于sql server)
|
||||
@@ -29,7 +28,7 @@ namespace OpenAuth.App
|
||||
var jsonArray = JsonHelper.Instance.Deserialize<JObject>(form.ContentData)["widgetList"];
|
||||
string tableName = form.DbName;
|
||||
//如果数据库已经存在该表,则不用创建
|
||||
var exist = _unitWork.FromSql<QueryStringObj>($"select '1' as value from sysobjects where name = '{tableName}' and type = 'U'").SingleOrDefault();
|
||||
var exist = _sugarClient.Ado.SqlQuery<QueryStringObj>($"select '1' as value from sysobjects where name = '{tableName}' and type = 'U'").SingleOrDefault();
|
||||
if (exist != null) return string.Empty;
|
||||
// 如果数据库没有指定的表,则创建表
|
||||
StringBuilder sql = new StringBuilder($"CREATE TABLE {tableName} ( [Id] varchar(50) COLLATE Chinese_PRC_CI_AS NOT NULL,"); //主键
|
||||
@@ -62,7 +61,7 @@ namespace OpenAuth.App
|
||||
var jsonArray = JsonHelper.Instance.Deserialize<JObject>(form.ContentData)["widgetList"];
|
||||
string tableName = form.DbName;
|
||||
//如果数据库已经存在该表,则不用创建
|
||||
var exist = _unitWork.FromSql<QueryStringObj>($"select distinct table_name as value from information_schema.tables where table_name ='{tableName}'").SingleOrDefault();
|
||||
var exist = _sugarClient.Ado.SqlQuery<QueryStringObj>($"select distinct table_name as value from information_schema.tables where table_name ='{tableName}'").SingleOrDefault();
|
||||
if (exist != null) return string.Empty;
|
||||
// 如果数据库没有指定的表,则创建表
|
||||
StringBuilder sql = new StringBuilder($"create table if not exists `{tableName}` ( Id varchar(50) not null primary key,"); //主键
|
||||
|
||||
@@ -4,19 +4,17 @@ using System.Threading.Tasks;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Utilities;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.Response;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
using SqlSugar;
|
||||
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class FormApp : BaseStringApp<Form,OpenAuthDBContext>
|
||||
public class FormApp : SqlSugarBaseApp<Form>
|
||||
{
|
||||
private IOptions<AppSetting> _appConfiguration;
|
||||
private IHttpContextAccessor _httpContextAccessor;
|
||||
@@ -44,19 +42,21 @@ namespace OpenAuth.App
|
||||
var user = _auth.GetCurrentUser().User;
|
||||
obj.CreateUserId = user.Id;
|
||||
obj.CreateUserName = user.Name;
|
||||
UnitWork.Add(obj);
|
||||
Repository.Insert(obj);
|
||||
if (!string.IsNullOrEmpty(obj.DbName))
|
||||
{
|
||||
var dbtype = _appConfiguration.Value.DbTypes[_httpContextAccessor.GetTenantId()];
|
||||
|
||||
UnitWork.ExecuteSql(FormFactory.CreateForm(obj, this.UnitWork).GetSql(obj, dbtype));
|
||||
var sql = FormFactory.CreateForm(obj, SugarClient).GetSql(obj, dbtype);
|
||||
if (!string.IsNullOrEmpty(sql))
|
||||
{
|
||||
SugarClient.Ado.ExecuteCommand(sql);
|
||||
}
|
||||
}
|
||||
UnitWork.Save();
|
||||
}
|
||||
|
||||
public void Update(Form obj)
|
||||
{
|
||||
Repository.Update(u => u.Id == obj.Id, u => new Form
|
||||
Repository.Update(u => new Form
|
||||
{
|
||||
FrmType = obj.FrmType,
|
||||
ContentData = obj.ContentData,
|
||||
@@ -69,12 +69,16 @@ namespace OpenAuth.App
|
||||
Description = obj.Description,
|
||||
OrgId = obj.OrgId,
|
||||
ModifyDate = DateTime.Now
|
||||
});
|
||||
}, u => u.Id == obj.Id);
|
||||
|
||||
if (!string.IsNullOrEmpty(obj.DbName))
|
||||
{
|
||||
var dbtype = _appConfiguration.Value.DbTypes[_httpContextAccessor.GetTenantId()];
|
||||
UnitWork.ExecuteSql(FormFactory.CreateForm(obj,this.UnitWork).GetSql(obj, dbtype));
|
||||
var sql = FormFactory.CreateForm(obj, SugarClient).GetSql(obj, dbtype);
|
||||
if (!string.IsNullOrEmpty(sql))
|
||||
{
|
||||
SugarClient.Ado.ExecuteCommand(sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,8 +88,8 @@ namespace OpenAuth.App
|
||||
return form.MapTo<FormResp>();
|
||||
}
|
||||
|
||||
public FormApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Form,OpenAuthDBContext> repository,
|
||||
IAuth auth, IOptions<AppSetting> appConfiguration, IHttpContextAccessor httpContextAccessor) : base(unitWork, repository, auth)
|
||||
public FormApp(ISqlSugarClient client,
|
||||
IAuth auth, IOptions<AppSetting> appConfiguration, IHttpContextAccessor httpContextAccessor) : base(client, auth)
|
||||
{
|
||||
_auth = auth;
|
||||
_appConfiguration = appConfiguration;
|
||||
|
||||
@@ -1,25 +1,24 @@
|
||||
using System;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
using Infrastructure;
|
||||
using SqlSugar;
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class FormFactory
|
||||
{
|
||||
public static IForm CreateForm(Form form, IUnitWork<OpenAuthDBContext> unitWork)
|
||||
public static IForm CreateForm(Form form, ISqlSugarClient sugarClient)
|
||||
{
|
||||
if (form.FrmType == Define.FORM_TYPE_DYNAMIC)
|
||||
{
|
||||
return new LeipiForm(unitWork);
|
||||
return new LeipiForm(sugarClient);
|
||||
}else if (form.FrmType == Define.FORM_TYPE_DEVELOP)
|
||||
{
|
||||
throw new Exception("自定义表单不需要创建数据库表");
|
||||
}
|
||||
else
|
||||
{
|
||||
return new DragForm(unitWork);
|
||||
return new DragForm(sugarClient);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,17 +2,16 @@
|
||||
using System.Text;
|
||||
using Infrastructure;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Interface;
|
||||
using OpenAuth.Repository.QueryObj;
|
||||
using SqlSugar;
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class LeipiForm : IForm
|
||||
{
|
||||
private IUnitWork<OpenAuthDBContext> _unitWork;
|
||||
public LeipiForm(IUnitWork<OpenAuthDBContext> unitWork)
|
||||
private ISqlSugarClient _sugarClient;
|
||||
public LeipiForm(ISqlSugarClient sugarClient)
|
||||
{
|
||||
_unitWork = unitWork;
|
||||
_sugarClient = sugarClient;
|
||||
}
|
||||
/**
|
||||
* 功能: 创建表单数据表格(基于sql server)
|
||||
@@ -25,7 +24,7 @@ namespace OpenAuth.App
|
||||
var jsonArray = JArray.Parse(form.ContentData);
|
||||
// 数据库名称
|
||||
string tableName = form.DbName;
|
||||
var exist = _unitWork.FromSql<QueryStringObj>($"select '1' as value from sysobjects where name = '{tableName}' and type = 'U'").SingleOrDefault();
|
||||
var exist = _sugarClient.Ado.SqlQuery<QueryStringObj>($"select '1' as value from sysobjects where name = '{tableName}' and type = 'U'").SingleOrDefault();
|
||||
if (exist != null) return string.Empty;
|
||||
// 创建数据表
|
||||
StringBuilder sql = new StringBuilder($"CREATE TABLE {tableName} ( [Id] varchar(50) COLLATE Chinese_PRC_CI_AS NOT NULL,"); //主键
|
||||
@@ -61,7 +60,7 @@ namespace OpenAuth.App
|
||||
var jsonArray = JArray.Parse(form.ContentData);
|
||||
// 数据库名称
|
||||
string tableName = form.DbName;
|
||||
var exist = _unitWork.FromSql<QueryStringObj>($"select distinct table_name as value from information_schema.tables where table_name ='{tableName}'").SingleOrDefault();
|
||||
var exist = _sugarClient.Ado.SqlQuery<QueryStringObj>($"select distinct table_name as value from information_schema.tables where table_name ='{tableName}'").SingleOrDefault();
|
||||
if (exist != null) return string.Empty;
|
||||
// 创建数据表
|
||||
StringBuilder sql = new StringBuilder($"create table if not exists `{tableName}` ( Id varchar(50) not null primary key,"); //主键
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
using System.Threading.Tasks;
|
||||
using Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.Response;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
using SqlSugar;
|
||||
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class FrmLeaveReqApp : BaseStringApp<FrmLeaveReq,OpenAuthDBContext>, ICustomerForm
|
||||
public class FrmLeaveReqApp : SqlSugarBaseApp<FrmLeaveReq>, ICustomerForm
|
||||
{
|
||||
private RevelanceManagerApp _revelanceApp;
|
||||
|
||||
@@ -22,18 +20,20 @@ namespace OpenAuth.App
|
||||
{
|
||||
return new PagedDynamicDataResp
|
||||
{
|
||||
Count = await Repository.CountAsync(null),
|
||||
Data = await Repository.Find(request.page, request.limit, "Id desc").ToListAsync()
|
||||
Count = await SugarClient.Queryable<FrmLeaveReq>().CountAsync(),
|
||||
Data = await SugarClient.Queryable<FrmLeaveReq>().OrderByDescending(u => u.Id)
|
||||
.Skip((request.page - 1) * request.limit)
|
||||
.Take(request.limit).ToListAsync()
|
||||
};
|
||||
}
|
||||
|
||||
public void Add(FrmLeaveReq obj)
|
||||
{
|
||||
Repository.Add(obj);
|
||||
Repository.Insert(obj);
|
||||
}
|
||||
|
||||
public FrmLeaveReqApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<FrmLeaveReq,OpenAuthDBContext> repository,
|
||||
RevelanceManagerApp app,IAuth auth) : base(unitWork, repository, auth)
|
||||
public FrmLeaveReqApp(ISqlSugarClient client,
|
||||
RevelanceManagerApp app,IAuth auth) : base(client, auth)
|
||||
{
|
||||
_revelanceApp = app;
|
||||
}
|
||||
@@ -48,13 +48,13 @@ namespace OpenAuth.App
|
||||
public void Update(string flowInstanceId, string frmData)
|
||||
{
|
||||
var req = JsonHelper.Instance.Deserialize<FrmLeaveReq>(frmData);
|
||||
UnitWork.Update<FrmLeaveReq>(u => u.FlowInstanceId == flowInstanceId, u => new FrmLeaveReq
|
||||
Repository.Update(u => new FrmLeaveReq
|
||||
{
|
||||
UserName = req.UserName,
|
||||
RequestComment = req.RequestComment,
|
||||
RequestType = req.RequestType
|
||||
//补充其他需要更新的字段
|
||||
});
|
||||
}, u => u.FlowInstanceId == flowInstanceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,17 +6,15 @@ using Infrastructure.Helpers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
using SqlSugar;
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class RevelanceManagerApp : BaseStringApp<Relevance,OpenAuthDBContext>
|
||||
public class RevelanceManagerApp : SqlSugarBaseApp<Relevance>
|
||||
{
|
||||
private readonly ILogger<RevelanceManagerApp> _logger;
|
||||
public RevelanceManagerApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Relevance,OpenAuthDBContext> repository, IAuth auth, ILogger<RevelanceManagerApp> logger) : base(unitWork,
|
||||
repository, auth)
|
||||
public RevelanceManagerApp(ISqlSugarClient client, IAuth auth, ILogger<RevelanceManagerApp> logger) : base(client, auth)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
@@ -38,7 +36,7 @@ namespace OpenAuth.App
|
||||
/// <param name="idMaps"></param>
|
||||
public void Assign(string key, ILookup<string, string> idMaps)
|
||||
{
|
||||
UnitWork.BatchAdd((from sameVals in idMaps
|
||||
SugarClient.Insertable((from sameVals in idMaps
|
||||
from value in sameVals
|
||||
select new Relevance
|
||||
{
|
||||
@@ -46,8 +44,7 @@ namespace OpenAuth.App
|
||||
FirstId = sameVals.Key,
|
||||
SecondId = value,
|
||||
OperateTime = TimeHelper.Now
|
||||
}).ToArray());
|
||||
UnitWork.Save();
|
||||
}).ToArray()).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -82,7 +79,7 @@ namespace OpenAuth.App
|
||||
_logger.LogInformation($"start=> delete {key} {sameVals.Key} {value}");
|
||||
try
|
||||
{
|
||||
UnitWork.Delete<Relevance>(u => u.RelKey == key && u.FirstId == sameVals.Key && u.SecondId == value);
|
||||
SugarClient.Deleteable<Relevance>().Where(u => u.RelKey == key && u.FirstId == sameVals.Key && u.SecondId == value).ExecuteCommand();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -95,7 +92,7 @@ namespace OpenAuth.App
|
||||
|
||||
public void DeleteBy(string key, params string[] firstIds)
|
||||
{
|
||||
UnitWork.Delete<Relevance>(u => firstIds.Contains(u.FirstId) && u.RelKey == key);
|
||||
SugarClient.Deleteable<Relevance>().Where(u => firstIds.Contains(u.FirstId) && u.RelKey == key).ExecuteCommand();
|
||||
}
|
||||
|
||||
|
||||
@@ -110,12 +107,12 @@ namespace OpenAuth.App
|
||||
{
|
||||
if (returnSecondIds)
|
||||
{
|
||||
return Repository.Find(u => u.RelKey == key
|
||||
return SugarClient.Queryable<Relevance>().Where(u => u.RelKey == key
|
||||
&& ids.Contains(u.FirstId)).Select(u => u.SecondId).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return Repository.Find(u => u.RelKey == key
|
||||
return SugarClient.Queryable<Relevance>().Where(u => u.RelKey == key
|
||||
&& ids.Contains(u.SecondId)).Select(u => u.FirstId).ToList();
|
||||
}
|
||||
}
|
||||
@@ -129,7 +126,7 @@ namespace OpenAuth.App
|
||||
/// <returns></returns>
|
||||
public List<string> Get(string key, string firstId, string secondId)
|
||||
{
|
||||
return Repository.Find(u => u.RelKey == key && u.FirstId == firstId && u.SecondId == secondId)
|
||||
return SugarClient.Queryable<Relevance>().Where(u => u.RelKey == key && u.FirstId == firstId && u.SecondId == secondId)
|
||||
.Select(u => u.ThirdId).ToList();
|
||||
}
|
||||
|
||||
@@ -157,8 +154,7 @@ namespace OpenAuth.App
|
||||
});
|
||||
}
|
||||
|
||||
UnitWork.BatchAdd(relevances.ToArray());
|
||||
UnitWork.Save();
|
||||
SugarClient.Insertable(relevances).ExecuteCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -182,10 +178,10 @@ namespace OpenAuth.App
|
||||
{
|
||||
foreach (var property in request.Properties)
|
||||
{
|
||||
UnitWork.Delete<Relevance>(u => u.RelKey == Define.ROLEDATAPROPERTY
|
||||
SugarClient.Deleteable<Relevance>().Where(u => u.RelKey == Define.ROLEDATAPROPERTY
|
||||
&& u.FirstId == request.RoleId
|
||||
&& u.SecondId == request.ModuleCode
|
||||
&& u.ThirdId == property);
|
||||
&& u.ThirdId == property).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -196,21 +192,19 @@ namespace OpenAuth.App
|
||||
/// <param name="request"></param>
|
||||
public void AssignRoleUsers(AssignRoleUsers request)
|
||||
{
|
||||
UnitWork.ExecuteWithTransaction(() =>
|
||||
{
|
||||
//删除以前的所有用户
|
||||
UnitWork.Delete<Relevance>(u => u.SecondId == request.RoleId && u.RelKey == Define.USERROLE);
|
||||
//批量分配用户角色
|
||||
UnitWork.BatchAdd((from firstId in request.UserIds
|
||||
SugarClient.Ado.BeginTran();
|
||||
//删除以前的所有用户
|
||||
SugarClient.Deleteable<Relevance>().Where(u => u.SecondId == request.RoleId && u.RelKey == Define.USERROLE).ExecuteCommand();
|
||||
//批量分配用户角色
|
||||
SugarClient.Insertable((from firstId in request.UserIds
|
||||
select new Relevance
|
||||
{
|
||||
RelKey = Define.USERROLE,
|
||||
FirstId = firstId,
|
||||
SecondId = request.RoleId,
|
||||
OperateTime = TimeHelper.Now
|
||||
}).ToArray());
|
||||
UnitWork.Save();
|
||||
});
|
||||
}).ToArray()).ExecuteCommand();
|
||||
SugarClient.Ado.CommitTran();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -219,21 +213,19 @@ namespace OpenAuth.App
|
||||
/// <param name="request"></param>
|
||||
public void AssignOrgUsers(AssignOrgUsers request)
|
||||
{
|
||||
UnitWork.ExecuteWithTransaction(() =>
|
||||
{
|
||||
//删除以前的所有用户
|
||||
UnitWork.Delete<Relevance>(u => u.SecondId == request.OrgId && u.RelKey == Define.USERORG);
|
||||
//批量分配用户角色
|
||||
UnitWork.BatchAdd((from firstId in request.UserIds
|
||||
SugarClient.Ado.BeginTran();
|
||||
//删除以前的所有用户
|
||||
SugarClient.Deleteable<Relevance>().Where(u => u.SecondId == request.OrgId && u.RelKey == Define.USERORG).ExecuteCommand();
|
||||
//批量分配用户角色
|
||||
SugarClient.Insertable((from firstId in request.UserIds
|
||||
select new Relevance
|
||||
{
|
||||
RelKey = Define.USERORG,
|
||||
FirstId = firstId,
|
||||
SecondId = request.OrgId,
|
||||
OperateTime = TimeHelper.Now
|
||||
}).ToArray());
|
||||
UnitWork.Save();
|
||||
});
|
||||
}).ToArray()).ExecuteCommand();
|
||||
SugarClient.Ado.CommitTran();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -242,21 +234,19 @@ namespace OpenAuth.App
|
||||
/// <param name="request"></param>
|
||||
public void AssignRoleResources(AssignRoleResources request)
|
||||
{
|
||||
UnitWork.ExecuteWithTransaction(() =>
|
||||
{
|
||||
//删除以前的所有资源
|
||||
UnitWork.Delete<Relevance>(u => u.FirstId == request.RoleId && u.RelKey == Define.ROLERESOURCE);
|
||||
//批量分配角色资源
|
||||
UnitWork.BatchAdd((from firstId in request.ResourceIds
|
||||
SugarClient.Ado.BeginTran();
|
||||
//删除以前的所有资源
|
||||
SugarClient.Deleteable<Relevance>().Where(u => u.FirstId == request.RoleId && u.RelKey == Define.ROLERESOURCE).ExecuteCommand();
|
||||
//批量分配角色资源
|
||||
SugarClient.Insertable((from firstId in request.ResourceIds
|
||||
select new Relevance
|
||||
{
|
||||
RelKey = Define.ROLERESOURCE,
|
||||
FirstId = request.RoleId,
|
||||
SecondId = firstId,
|
||||
OperateTime = TimeHelper.Now
|
||||
}).ToArray());
|
||||
UnitWork.Save();
|
||||
});
|
||||
}).ToArray()).ExecuteCommand();
|
||||
SugarClient.Ado.CommitTran();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,15 @@
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.Response;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
using SqlSugar;
|
||||
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class SysLogApp : BaseStringApp<SysLog,OpenAuthDBContext>
|
||||
public class SysLogApp : SqlSugarBaseApp<SysLog>
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
@@ -20,7 +18,7 @@ namespace OpenAuth.App
|
||||
public async Task<PagedDynamicDataResp> Load(QuerySysLogListReq request)
|
||||
{
|
||||
var result = new PagedDynamicDataResp();
|
||||
var objs = UnitWork.Find<SysLog>(null);
|
||||
var objs = SugarClient.Queryable<SysLog>();
|
||||
if (!string.IsNullOrEmpty(request.key))
|
||||
{
|
||||
objs = objs.Where(u => u.Content.Contains(request.key) || u.Id.Contains(request.key));
|
||||
@@ -37,19 +35,19 @@ namespace OpenAuth.App
|
||||
{
|
||||
//程序类型取入口应用的名称,可以根据自己需要调整
|
||||
obj.Application = Assembly.GetEntryAssembly().FullName.Split(',')[0];
|
||||
Repository.Add(obj);
|
||||
Repository.Insert(obj);
|
||||
}
|
||||
|
||||
public void Update(SysLog obj)
|
||||
{
|
||||
UnitWork.Update<SysLog>(u => u.Id == obj.Id, u => new SysLog
|
||||
Repository.Update(u => new SysLog
|
||||
{
|
||||
//todo:要修改的字段赋值
|
||||
});
|
||||
}, u => u.Id == obj.Id);
|
||||
|
||||
}
|
||||
|
||||
public SysLogApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<SysLog,OpenAuthDBContext> repository) : base(unitWork, repository, null)
|
||||
public SysLogApp(ISqlSugarClient client) : base(client, null)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user