From 8b890a927138390b606008f93bc8ebc52c0cc3c7 Mon Sep 17 00:00:00 2001 From: chenchun <454313500@qq.com> Date: Sun, 28 Jul 2024 00:25:00 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90saas=E5=A4=9A?= =?UTF-8?q?=E7=A7=9F=E6=88=B7=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SqlSugarDbContext.cs | 6 +- .../TenantService.cs | 59 ++++++++++--------- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarDbContext.cs b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarDbContext.cs index cdb050d8..5fa812af 100644 --- a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarDbContext.cs +++ b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarDbContext.cs @@ -57,12 +57,10 @@ namespace Yi.Framework.SqlSugarCore connectionCreator.DataExecuted = DataExecuted; connectionCreator.OnLogExecuting = OnLogExecuting; connectionCreator.OnLogExecuted = OnLogExecuted; - var currentConnection = GetCurrentConnectionString(); - var currentDbType = GetCurrentDbType(); SqlSugarClient = new SqlSugarClient(connectionCreator.Build(action: options => { - options.ConnectionString = currentConnection; - + options.ConnectionString = GetCurrentConnectionString(); + options.DbType = GetCurrentDbType(); })); connectionCreator.SetDbAop(SqlSugarClient); } diff --git a/Yi.Abp.Net8/module/tenant-management/Yi.Framework.TenantManagement.Application/TenantService.cs b/Yi.Abp.Net8/module/tenant-management/Yi.Framework.TenantManagement.Application/TenantService.cs index 11979e9f..618bda62 100644 --- a/Yi.Abp.Net8/module/tenant-management/Yi.Framework.TenantManagement.Application/TenantService.cs +++ b/Yi.Abp.Net8/module/tenant-management/Yi.Framework.TenantManagement.Application/TenantService.cs @@ -18,11 +18,15 @@ namespace Yi.Framework.TenantManagement.Application /// /// 租户管理 /// - public class TenantService : YiCrudAppService, ITenantService + public class TenantService : + YiCrudAppService, ITenantService { private ISqlSugarRepository _repository; private IDataSeeder _dataSeeder; - public TenantService(ISqlSugarRepository repository, IDataSeeder dataSeeder) : base(repository) + + public TenantService(ISqlSugarRepository repository, IDataSeeder dataSeeder) : + base(repository) { _repository = repository; _dataSeeder = dataSeeder; @@ -47,9 +51,11 @@ namespace Yi.Framework.TenantManagement.Application { RefAsync total = 0; - var entities = await _repository._DbQueryable.WhereIF(!string.IsNullOrEmpty(input.Name), x => x.Name.Contains(input.Name!)) - .WhereIF(input.StartTime is not null && input.EndTime is not null, x => x.CreationTime >= input.StartTime && x.CreationTime <= input.EndTime) - .ToPageListAsync(input.SkipCount, input.MaxResultCount, total); + var entities = await _repository._DbQueryable + .WhereIF(!string.IsNullOrEmpty(input.Name), x => x.Name.Contains(input.Name!)) + .WhereIF(input.StartTime is not null && input.EndTime is not null, + x => x.CreationTime >= input.StartTime && x.CreationTime <= input.EndTime) + .ToPageListAsync(input.SkipCount, input.MaxResultCount, total); return new PagedResultDto(total, await MapToGetListOutputDtosAsync(entities)); } @@ -75,6 +81,7 @@ namespace Yi.Framework.TenantManagement.Application { throw new UserFriendlyException("创建失败,当前租户已存在"); } + return await base.CreateAsync(input); } @@ -118,9 +125,8 @@ namespace Yi.Framework.TenantManagement.Application using (CurrentTenant.Change(id)) { await CodeFirst(this.LazyServiceProvider); - await _dataSeeder.SeedAsync(id); + await _dataSeeder.SeedAsync(id); } - } private async Task CodeFirst(IServiceProvider service) @@ -134,27 +140,24 @@ namespace Yi.Framework.TenantManagement.Application db = await _repository.GetDbContextAsync(); //尝试创建数据库 db.DbMaintenance.CreateDatabase(); - await uow.CompleteAsync(); + + List types = new List(); + foreach (var module in moduleContainer.Modules) + { + types.AddRange(module.Assembly.GetTypes() + .Where(x => x.GetCustomAttribute() == null) + .Where(x => x.GetCustomAttribute() != null) + .Where(x => x.GetCustomAttribute() is null) + .Where(x => x.GetCustomAttribute() is null)); + } + + if (types.Count > 0) + { + db.CodeFirst.InitTables(types.ToArray()); + } + + await uow.CompleteAsync(); } - - - - - - List types = new List(); - foreach (var module in moduleContainer.Modules) - { - types.AddRange(module.Assembly.GetTypes() - .Where(x => x.GetCustomAttribute() == null) - .Where(x => x.GetCustomAttribute() != null) - .Where(x=>x.GetCustomAttribute() is null) - .Where(x => x.GetCustomAttribute() is null)); - } - if (types.Count > 0) - { - db.CopyNew().CodeFirst.InitTables(types.ToArray()); - } - } } -} +} \ No newline at end of file From 2eaa5f5bb61314fc89b13f766c122272ea58a7fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Sun, 28 Jul 2024 23:40:29 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=E5=A4=9A?= =?UTF-8?q?=E7=A7=9F=E6=88=B7md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TenantService.cs | 3 +- Yi.Bbs.Vue3/src/views/chathub/Index.vue | 30 +++++-- Yi.Doc.Md/02.框架功能模块教程/17.多租户.md | 80 ++++++++++++++++++ Yi.Doc.Md/02.框架功能模块教程/image-1.png | Bin 0 -> 20424 bytes Yi.Doc.Md/02.框架功能模块教程/image-2.png | Bin 0 -> 46853 bytes Yi.Doc.Md/02.框架功能模块教程/image-3.png | Bin 0 -> 9714 bytes Yi.Doc.Md/02.框架功能模块教程/image-4.png | Bin 0 -> 46931 bytes Yi.Doc.Md/02.框架功能模块教程/image-5.png | Bin 0 -> 58729 bytes Yi.Doc.Md/02.框架功能模块教程/image-6.png | Bin 0 -> 103950 bytes Yi.Doc.Md/02.框架功能模块教程/image-7.png | Bin 0 -> 95454 bytes Yi.Doc.Md/02.框架功能模块教程/image-8.png | Bin 0 -> 32436 bytes Yi.Doc.Md/02.框架功能模块教程/image.png | Bin 0 -> 77015 bytes 12 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 Yi.Doc.Md/02.框架功能模块教程/17.多租户.md create mode 100644 Yi.Doc.Md/02.框架功能模块教程/image-1.png create mode 100644 Yi.Doc.Md/02.框架功能模块教程/image-2.png create mode 100644 Yi.Doc.Md/02.框架功能模块教程/image-3.png create mode 100644 Yi.Doc.Md/02.框架功能模块教程/image-4.png create mode 100644 Yi.Doc.Md/02.框架功能模块教程/image-5.png create mode 100644 Yi.Doc.Md/02.框架功能模块教程/image-6.png create mode 100644 Yi.Doc.Md/02.框架功能模块教程/image-7.png create mode 100644 Yi.Doc.Md/02.框架功能模块教程/image-8.png create mode 100644 Yi.Doc.Md/02.框架功能模块教程/image.png diff --git a/Yi.Abp.Net8/module/tenant-management/Yi.Framework.TenantManagement.Application/TenantService.cs b/Yi.Abp.Net8/module/tenant-management/Yi.Framework.TenantManagement.Application/TenantService.cs index 618bda62..b723d412 100644 --- a/Yi.Abp.Net8/module/tenant-management/Yi.Framework.TenantManagement.Application/TenantService.cs +++ b/Yi.Abp.Net8/module/tenant-management/Yi.Framework.TenantManagement.Application/TenantService.cs @@ -134,10 +134,9 @@ namespace Yi.Framework.TenantManagement.Application var moduleContainer = service.GetRequiredService(); //没有数据库,不能创工作单元,创建库,先关闭 - ISqlSugarClient db = null; using (var uow = UnitOfWorkManager.Begin(requiresNew: true, isTransactional: false)) { - db = await _repository.GetDbContextAsync(); + ISqlSugarClient db = await _repository.GetDbContextAsync(); //尝试创建数据库 db.DbMaintenance.CreateDatabase(); diff --git a/Yi.Bbs.Vue3/src/views/chathub/Index.vue b/Yi.Bbs.Vue3/src/views/chathub/Index.vue index ec1bf0ed..5f0e8623 100644 --- a/Yi.Bbs.Vue3/src/views/chathub/Index.vue +++ b/Yi.Bbs.Vue3/src/views/chathub/Index.vue @@ -16,6 +16,7 @@ import '@/assets/atom-one-dark.css'; import '@/assets/github-markdown.css'; import hljs from "highlight.js"; +const isShowTipNumber=ref(10); const router = useRouter(); //聊天存储 const chatStore = useChatStore(); @@ -34,6 +35,18 @@ const inputListDataStore = ref([{ key: "all", value: "" }, { key: "ai", value: " //AI聊天临时存储 const sendAiChatContext = ref([]); +let timerTip=null; +//倒计时显示tip +const startCountTip = () => { + timerTip = setInterval(() => { + if (isShowTipNumber.value > 0) { + isShowTipNumber.value--; + } else { + clearInterval(timerTip); // 倒计时结束 + } + }, 1000); + }; + //当前聊天框显示的消息 const currentMsgContext = computed(() => { if (selectIsAll()) { @@ -93,7 +106,7 @@ let codeCopyDic=[]; //code部分处理、高亮 const codeHandler = (code, language) => { const codeIndex = parseInt(Date.now() + "") + Math.floor(Math.random() * 10000000); - console.log(codeIndex,"codeIndex"); + //console.log(codeIndex,"codeIndex"); // 格式化第一行是右侧language和 “复制” 按钮; if (code) { const navCode = navHandler(code) @@ -179,12 +192,16 @@ onMounted(async () => { } chatStore.setMsgList((await getChatAccountMessageList()).data); chatStore.setUserList((await getChatUserList()).data); + startCountTip(); }) onUnmounted(() => { if (timer != null) { clearInterval(timer) } - + if (timerTip != null) { + clearInterval(timerTip) + } + }) //代码copy事件 @@ -370,8 +387,9 @@ const getLastMessage = ((receiveId, itemType) => {