From a38b50675f2cf8e813bd337ca2f9d9456cc421d3 Mon Sep 17 00:00:00 2001 From: dengjunjie <dengjunjie@hnkhzn.com> Date: 星期四, 17 十月 2024 09:50:14 +0800 Subject: [PATCH] WCS --- 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_Services/Sys_TenantService.cs | 80 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 80 insertions(+), 0 deletions(-) diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Services/Sys_TenantService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Services/Sys_TenantService.cs" new file mode 100644 index 0000000..f6bf57a --- /dev/null +++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Services/Sys_TenantService.cs" @@ -0,0 +1,80 @@ +锘縰sing SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WIDESEA_Core; +using WIDESEA_Core.AOP; +using WIDESEA_Core.BaseRepository; +using WIDESEA_Core.BaseServices; +using WIDESEA_Core.Const; +using WIDESEA_Core.Helper; +using WIDESEA_Core.Seed; +using WIDESEA_IRepository; +using WIDESEA_IServices; +using WIDESEA_Model.Models; + +namespace WIDESEA_Services +{ + public class Sys_TenantService : ServiceBase<Sys_Tenant, ISys_TenantRepository>, ISys_TenantService + { + private IUnitOfWorkManage _unitOfWorkManage; + public Sys_TenantService(ISys_TenantRepository BaseDal, IUnitOfWorkManage unitOfWorkManage) : base(BaseDal) + { + _unitOfWorkManage = unitOfWorkManage; + } + + public WebResponseContent InitTenantInfo(string tenantName, int tenantType) + { + WebResponseContent content = new WebResponseContent(); + try + { + Sys_Tenant tenant = new Sys_Tenant() + { + ConnectionString = TenantConst.DBConStr, + DbType = 1, + Status = 1, + TenantName = tenantName, + TenantType = tenantType, + CreateDate = DateTime.Now, + Creater = "1111" + }; + + int tenantId = BaseDal.Db.Insertable(tenant).ExecuteReturnIdentity(); + + tenant = BaseDal.QueryFirst(x => x.TenantId == tenantId); + + tenant.ConnectionString = string.Format(TenantConst.DBConStr, ".", "Tenant_WMSDB_" + tenantId, "sa", "P@ssw0rd").EncryptDES(AppSecret.DB); + + BaseDal.UpdateData(tenant); + + InitTenantDb(tenant); + content = WebResponseContent.Instance.OK(); + } + catch (Exception ex) + { + content = WebResponseContent.Instance.Error(ex.Message); + } + return content; + } + + public void InitTenantDb(Sys_Tenant tenant) + { + string conStr = tenant.ConnectionString.DecryptDES(AppSecret.DB); + + ConnectionConfig connectionConfig = new ConnectionConfig() + { + ConfigId = tenant.TenantId, + ConnectionString = conStr, + DbType = (DbType)tenant.DbType, + IsAutoCloseConnection = true, + AopEvents = new AopEvents() + { + DataExecuting = SqlSugarAop.DataExecuting + } + }; + DBSeed.InitTenantSeedAsync(Db.AsTenant(), connectionConfig); + } + } +} -- Gitblit v1.9.3