🔄refactor: 调整为SqlSugar

This commit is contained in:
yubaolee
2026-05-24 23:34:27 +08:00
parent 237fc49f2f
commit d2c8f783e1
10 changed files with 130 additions and 166 deletions

View File

@@ -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;