diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Base/MiaoYuBase.cs b/src/0-core/HuanMeng.MiaoYu.Code/Base/MiaoYuBase.cs index 49979f2..bb13c3f 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/Base/MiaoYuBase.cs +++ b/src/0-core/HuanMeng.MiaoYu.Code/Base/MiaoYuBase.cs @@ -4,8 +4,10 @@ using HuanMeng.DotNetCore.Base; using HuanMeng.DotNetCore.JwtInfrastructure; using HuanMeng.DotNetCore.JwtInfrastructure.Interface; using HuanMeng.DotNetCore.MultiTenant; +using HuanMeng.DotNetCore.MultiTenant.Contract; using HuanMeng.MiaoYu.Code.Cache; using HuanMeng.MiaoYu.Code.DataAccess; + using HuanMeng.MiaoYu.Code.TencentUtile; using HuanMeng.MiaoYu.Code.Users.UserAccount; using HuanMeng.MiaoYu.Code.Users.UserAccount.Contract; @@ -58,17 +60,17 @@ namespace HuanMeng.MiaoYu.Code.Base /// /// /// - private TenantInfo _tenantInfo; + private ITenantInfo _tenantInfo; /// /// 租户信息 /// - public TenantInfo TenantInfo + public ITenantInfo TenantInfo { get { if (_tenantInfo == null) { - _tenantInfo = _serviceProvider.GetRequiredService(); + _tenantInfo = _serviceProvider.GetRequiredService(); } return _tenantInfo; } @@ -277,6 +279,29 @@ namespace HuanMeng.MiaoYu.Code.Base } } #endregion + + #region 字典数据 + + /// + /// 字典数据列表 + /// + private IDictionaryInfo _dictionaryInfo; + /// + /// 字典数据列表 + /// + public IDictionaryInfo DictionaryInfo + { + + get + { + if (_dictionaryInfo == null) + { + _dictionaryInfo = _serviceProvider.GetRequiredService(); + } + return _dictionaryInfo; + } + } + #endregion } /// diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Category/CategoryBLL.cs b/src/0-core/HuanMeng.MiaoYu.Code/Category/CategoryBLL.cs index 01763b8..9348ffc 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/Category/CategoryBLL.cs +++ b/src/0-core/HuanMeng.MiaoYu.Code/Category/CategoryBLL.cs @@ -1,4 +1,6 @@ using HuanMeng.DotNetCore.Base; +using HuanMeng.MiaoYu.Code.Cache; +using HuanMeng.MiaoYu.Code.SysDictionary.Contract; using HuanMeng.MiaoYu.Model.Dto.Category; using HuanMeng.MiaoYu.Model.Dto.Character; using HuanMeng.MiaoYu.Model.Dto.Find; @@ -67,6 +69,21 @@ namespace HuanMeng.MiaoYu.Code.Category public BaseResponse>> GetRecommendList() { List> recommendDtos = new List>(); + var menuList = Dao.daoDbMiaoYu.context.T_Category_Child_Menu.Where(it => it.IsEnabled).ToList(); + var node = DictionaryInfo.GetDictionariesChildNode(T_Sys_DictionaryEnum.categorymenu); + node.ForEach(_node => + { + var menu = menuList.Where(it => it.Type == _node.ExtendValue).OrderBy(it => it.OrderById).ToList(); + if (menu?.Count > 0) + { + RecommendDto banner = new RecommendDto(); + banner.Title = _node.Name; + banner.Type = _node.Value;//动作Id + var categoryPageRegion = CategoryPageRegionExtend.GetCategoryPageRegion(RecommendTypeEnum.banner, menu, this.MiaoYuCache); + banner.Data = categoryPageRegion.GetRecommendData(); + + } + }); #region 假数据 RecommendDto banner = new RecommendDto(); banner.Title = "Banner"; @@ -112,7 +129,7 @@ namespace HuanMeng.MiaoYu.Code.Category data.ActionType = RecommendActionTypeEnum.Chat.ToString(); data.ActionId = data.Id.ToString(); data.ImageUrl = x.BgImage;//data.BgImage; - + tuijian.Data.Add(data); xiaoshuo.Data.Add(data); index++; diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Category/CategoryPageRegionExtend.cs b/src/0-core/HuanMeng.MiaoYu.Code/Category/CategoryPageRegionExtend.cs new file mode 100644 index 0000000..aba58c0 --- /dev/null +++ b/src/0-core/HuanMeng.MiaoYu.Code/Category/CategoryPageRegionExtend.cs @@ -0,0 +1,110 @@ +using AutoMapper; + +using HuanMeng.MiaoYu.Code.Cache; +using HuanMeng.MiaoYu.Code.Category.Contract; +using HuanMeng.MiaoYu.Model.Dto.Find; +using HuanMeng.MiaoYu.Model.EnumModel.Find; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace HuanMeng.MiaoYu.Code.Category +{ + /// + /// + /// + public static class CategoryPageRegionExtend + { + //, RecommendTypeEnum recommend + + /// + /// 获取页面返回类型 + /// + /// + /// + /// + /// + public static ICategoryPageRegion GetCategoryPageRegion(RecommendTypeEnum recommend, List menu, MiaoYuCache miaoYuCache) + { + if (recommend == RecommendTypeEnum.tuijian || recommend == RecommendTypeEnum.xiaoshuo) + { + return new CategoryPageRegionBanner(menu, miaoYuCache); + } + if (recommend == RecommendTypeEnum.banner) + { + return new CategoryPageRegionBanner(menu, miaoYuCache); + } + + return new CategoryPageRegionBanner(menu, miaoYuCache); + } + } + + /// + ///发现页-banner位实现 + /// + public class CategoryPageRegionBanner(List menu, MiaoYuCache miaoYuCache) : ICategoryPageRegion + { + public List GetRecommendData() + { + var data = new List(); + menu.ForEach(_menu => + { + data.Add(new CommonRecommendData + { + ActionId = _menu.ActionId, + ActionType = _menu.ActionType, + ImageUrl = _menu.ImageId.GetImageUrl(miaoYuCache), + }); + }); + return data; + } + } + + /// + /// 发现页-小说聊天 + /// + /// + /// + public class CategoryPageRegionChat(List menu, MiaoYuCache miaoYuCache) : ICategoryPageRegion + { + public List GetRecommendData() + { + var data = new List(); + menu.ForEach(m => + { + var d = new DataListDto(); + d.ActionType = RecommendActionTypeEnum.Chat.ToString(); + d.ActionId = m.Id.ToString(); + d.ImageUrl = m.ImageUrl;//data.BgImage; + if (m.ActionType == RecommendActionTypeEnum.Chat.ToString()) + { + + if (!int.TryParse(m.ActionId, out var chatId)) + { + return; + } + var character = miaoYuCache.CharacterList.FirstOrDefault(it => it.Id == chatId); + if (character == null) + { + return; + } + if (string.IsNullOrEmpty(d.ImageUrl)) + { + d.ImageUrl = character.BgImage; + } + d.Name = character.Name; + d.Biography = character.Biography; + d.Label = character.Label; + d.Gender = character.Gender; + + } + data.Add(d); + }); + return data; + } + } +} diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Category/Contract/ICategoryPageRegion.cs b/src/0-core/HuanMeng.MiaoYu.Code/Category/Contract/ICategoryPageRegion.cs new file mode 100644 index 0000000..0826162 --- /dev/null +++ b/src/0-core/HuanMeng.MiaoYu.Code/Category/Contract/ICategoryPageRegion.cs @@ -0,0 +1,25 @@ +using HuanMeng.MiaoYu.Model.Dto.Find; +using HuanMeng.MiaoYu.Model.EnumModel.Find; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HuanMeng.MiaoYu.Code.Category.Contract +{ + /// + /// 发现页区域配置 + /// + public interface ICategoryPageRegion + { + + /// + /// 根据页面类型返回页面数据 + /// + /// + /// + List GetRecommendData(); + } +} diff --git a/src/0-core/HuanMeng.MiaoYu.Code/DataAccess/DAO.cs b/src/0-core/HuanMeng.MiaoYu.Code/DataAccess/DAO.cs index ec9e72c..7ec8b6b 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/DataAccess/DAO.cs +++ b/src/0-core/HuanMeng.MiaoYu.Code/DataAccess/DAO.cs @@ -1,5 +1,6 @@ using HuanMeng.DotNetCore.Base; using HuanMeng.DotNetCore.MultiTenant; +using HuanMeng.DotNetCore.MultiTenant.Contract; using HuanMeng.MiaoYu.Model.DbSqlServer.Db_MiaoYu; using Microsoft.Extensions.DependencyInjection; @@ -18,21 +19,21 @@ namespace HuanMeng.MiaoYu.Code.DataAccess public class DAO : DaoBase { //private IMultiTenantProvider _multiTenantProvider; - private TenantInfo _tenantInfo; + private ITenantInfo _tenantInfo; /// /// 构造函数 /// /// public DAO(IServiceProvider serviceProvider) : base(serviceProvider) { - this._tenantInfo = serviceProvider.GetRequiredService(); + this._tenantInfo = serviceProvider.GetRequiredService(); } /// /// 构造函数 /// /// - public DAO(IServiceProvider serviceProvider, TenantInfo tenantInfo) : base(serviceProvider) + public DAO(IServiceProvider serviceProvider, ITenantInfo tenantInfo) : base(serviceProvider) { this._tenantInfo = tenantInfo; diff --git a/src/0-core/HuanMeng.MiaoYu.Code/GlobalUsings.cs b/src/0-core/HuanMeng.MiaoYu.Code/GlobalUsings.cs index 09519e3..82c03a5 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/GlobalUsings.cs +++ b/src/0-core/HuanMeng.MiaoYu.Code/GlobalUsings.cs @@ -6,3 +6,7 @@ global using System.Text.Json; global using System.Text.Json.Serialization; global using HuanMeng.MiaoYu.Model.EnumModel; global using HuanMeng.MiaoYu.Model.EnumModel.User; +global using System.Collections.Concurrent; +global using HuanMeng.MiaoYu.Code.SysDictionary.Contract; +global using HuanMeng.MiaoYu.Code.SysDictionary; +global using HuanMeng.MiaoYu.Code.SysDictionary.DictionaryNetwork; \ No newline at end of file diff --git a/src/0-core/HuanMeng.MiaoYu.Code/MultiTenantUtil/MiaoYuMultiTenantExtension.cs b/src/0-core/HuanMeng.MiaoYu.Code/MultiTenantUtil/MiaoYuMultiTenantExtension.cs index 3b0cee9..cbedf25 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/MultiTenantUtil/MiaoYuMultiTenantExtension.cs +++ b/src/0-core/HuanMeng.MiaoYu.Code/MultiTenantUtil/MiaoYuMultiTenantExtension.cs @@ -14,6 +14,7 @@ using Microsoft.Extensions.Configuration; using HuanMeng.DotNetCore.MultiTenant; using HuanMeng.MiaoYu.Model.DbSqlServer.Db_MiaoYu; using Microsoft.EntityFrameworkCore; +using HuanMeng.DotNetCore.MultiTenant.Contract; namespace HuanMeng.MiaoYu.Code.MultiTenantUtil { @@ -37,7 +38,7 @@ namespace HuanMeng.MiaoYu.Code.MultiTenantUtil //添加注入全部的多租户配置项 //builder.Services.AddSingleton(sunnySportsMultiTenantConfig); ////添加单个租户的配置项 - builder.Services.AddScoped(); + builder.Services.AddScoped(); ////添加教师端用户 //builder.Services.AddScoped(); //builder.Services.AddScoped(); @@ -46,7 +47,7 @@ namespace HuanMeng.MiaoYu.Code.MultiTenantUtil //添加系统数据库 builder.Services.AddDbContext((serviceProvider, options) => { - var m = serviceProvider.GetRequiredService(); + var m = serviceProvider.GetRequiredService(); string sunnySportConnectionString = ""; if (m != null) { diff --git a/src/0-core/HuanMeng.MiaoYu.Code/MultiTenantUtil/MiaoYuMultiTenantTenantMiddleware.cs b/src/0-core/HuanMeng.MiaoYu.Code/MultiTenantUtil/MiaoYuMultiTenantTenantMiddleware.cs index 1deb72a..3265436 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/MultiTenantUtil/MiaoYuMultiTenantTenantMiddleware.cs +++ b/src/0-core/HuanMeng.MiaoYu.Code/MultiTenantUtil/MiaoYuMultiTenantTenantMiddleware.cs @@ -1,4 +1,5 @@ using HuanMeng.DotNetCore.MultiTenant; +using HuanMeng.DotNetCore.MultiTenant.Contract; using Microsoft.AspNetCore.Http; @@ -34,7 +35,7 @@ namespace HuanMeng.MiaoYu.Code.MultiTenantUtil /// public virtual async Task Invoke(HttpContext context, IServiceProvider _serviceProvider, - TenantInfo tenantInfo, + ITenantInfo tenantInfo, MiaoYuMultiTenantConfig miaoYuMultiTenantConfig ) { diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Other/JwtTokenManageExtension.cs b/src/0-core/HuanMeng.MiaoYu.Code/Other/JwtTokenManageExtension.cs index abb1aac..b618a31 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/Other/JwtTokenManageExtension.cs +++ b/src/0-core/HuanMeng.MiaoYu.Code/Other/JwtTokenManageExtension.cs @@ -19,5 +19,5 @@ namespace HuanMeng.MiaoYu.Code.Other /// public static class JwtTokenManageExtension { - } + } } diff --git a/src/0-core/HuanMeng.MiaoYu.Code/SysDictionary/Contract/IDictionaryInfo.cs b/src/0-core/HuanMeng.MiaoYu.Code/SysDictionary/Contract/IDictionaryInfo.cs new file mode 100644 index 0000000..e4ca07a --- /dev/null +++ b/src/0-core/HuanMeng.MiaoYu.Code/SysDictionary/Contract/IDictionaryInfo.cs @@ -0,0 +1,44 @@ +using HuanMeng.MiaoYu.Model.Dto; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HuanMeng.MiaoYu.Code.SysDictionary.Contract +{ + /// + /// 字典数据 + /// + public interface IDictionaryInfo + { + /// + /// 获取全部的字典数据 + /// + /// + List GetDictionaries(); + + /// + /// + /// + /// + /// + T_Sys_Dictionary GetDictionaryNode(T_Sys_DictionaryEnum dictionaryEnum); + + /// + /// 获取对象项目的字段数据 + /// + /// + /// + List GetDictionariesChildNode(string ProjectCode); + + /// + /// 获取对象项目的字段数据 + /// + /// + /// + List GetDictionariesChildNode(T_Sys_DictionaryEnum dictionaryEnum); + + } +} diff --git a/src/0-core/HuanMeng.MiaoYu.Code/SysDictionary/Contract/IDictionaryInfoServer.cs b/src/0-core/HuanMeng.MiaoYu.Code/SysDictionary/Contract/IDictionaryInfoServer.cs new file mode 100644 index 0000000..0090390 --- /dev/null +++ b/src/0-core/HuanMeng.MiaoYu.Code/SysDictionary/Contract/IDictionaryInfoServer.cs @@ -0,0 +1,40 @@ +using HuanMeng.DotNetCore.MultiTenant.Contract; +using HuanMeng.MiaoYu.Model.Dto; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HuanMeng.MiaoYu.Code.SysDictionary.Contract +{ + /// + /// 字典服务 + /// + public interface IDictionaryInfoServer + { + /// + /// 初始化的时候调用 + /// + Task Initialization(); + /// + /// 获取全部的字典数据 + /// + /// + List GetDictionaries(); + + /// + /// 获取全部的字典数据 + /// + /// + List GetDictionaries(ITenantInfo tenantInfo); + + /// + /// + /// + /// + /// + List this[ITenantInfo tenantInfo] { get; } + } +} diff --git a/src/0-core/HuanMeng.MiaoYu.Code/SysDictionary/DictionaryInfoExtend.cs b/src/0-core/HuanMeng.MiaoYu.Code/SysDictionary/DictionaryInfoExtend.cs new file mode 100644 index 0000000..184287a --- /dev/null +++ b/src/0-core/HuanMeng.MiaoYu.Code/SysDictionary/DictionaryInfoExtend.cs @@ -0,0 +1,82 @@ +using HuanMeng.MiaoYu.Code.MultiTenantUtil; +using HuanMeng.MiaoYu.Code.SysDictionary.Contract; +using HuanMeng.MiaoYu.Code.SysDictionary.DictionaryNetwork; +using HuanMeng.MiaoYu.Model.Dto; + +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HuanMeng.MiaoYu.Code.SysDictionary +{ + /// + /// + /// + public static class DictionaryInfoExtend + { + public static void AddDictionaryInfo(this IHostApplicationBuilder builder) + { + builder.Services.AddSingleton(); + + builder.Services.AddScoped(); + builder.Services.AddHostedService(); + } + + + /// + /// 获取当前对象下的所有集合 + /// + /// + /// + /// + public static List GetChildDictionaries(this T_Sys_Dictionary dictionarie, List dictionaries) + { + List list = new List(); + dictionaries.Where(it => it.ParentId == dictionarie.Id).ToList()?.ForEach(it => + { + list.Add(it); + var _list = it.GetChildDictionaries(list); + list.AddRange(_list); + }); + return list; + } + + /// + /// 获取当前对象下的所有集合 + /// + /// + /// + /// + public static List GetChildDictionariesFind(this T_Sys_Dictionary dictionarie, List dictionaries) + { + List list = new List(); + + return dictionaries.Where(it => it.ParentId == dictionarie.Id).OrderBy(it=>it.Sort).ToList(); + } + + + } + + /// + /// + /// + /// + public class DictionaryInfoExtendServer(IDictionaryInfoServer dictionaryInfoServer) : IHostedService + { + public async Task StartAsync(CancellationToken cancellationToken) + { + await dictionaryInfoServer.Initialization(); + + } + + public Task StopAsync(CancellationToken cancellationToken) + { + return Task.CompletedTask; + } + } +} diff --git a/src/0-core/HuanMeng.MiaoYu.Code/SysDictionary/DictionaryNetwork/DictionaryInfoNetwork.cs b/src/0-core/HuanMeng.MiaoYu.Code/SysDictionary/DictionaryNetwork/DictionaryInfoNetwork.cs new file mode 100644 index 0000000..6aa22b5 --- /dev/null +++ b/src/0-core/HuanMeng.MiaoYu.Code/SysDictionary/DictionaryNetwork/DictionaryInfoNetwork.cs @@ -0,0 +1,68 @@ +using HuanMeng.DotNetCore.MultiTenant; +using HuanMeng.DotNetCore.MultiTenant.Contract; +using HuanMeng.MiaoYu.Code.SysDictionary.Contract; +using HuanMeng.MiaoYu.Model.Dto; + +using Microsoft.Extensions.Configuration; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HuanMeng.MiaoYu.Code.SysDictionary.DictionaryNetwork +{ + /// + /// 字典数据 + /// + /// + /// + public class DictionaryInfoNetwork(IDictionaryInfoServer dictionaryInfoServer, ITenantInfo tenantInfo) : IDictionaryInfo + { + private List? _dictionaryInfo = null; + /// + /// + /// + public List DictionaryInfo + { + get + { + if (_dictionaryInfo == null) + { + _dictionaryInfo = dictionaryInfoServer[tenantInfo]; + } + return _dictionaryInfo; + } + } + + public List GetDictionaries() + { + + return DictionaryInfo; + } + + public List GetDictionariesChildNode(string ProjectCode) + { + List t_Sys_Dictionaries = new List(); + + var list = DictionaryInfo.Where(it => it.ProjectCode == ProjectCode).OrderBy(it => it.Sort).ToList(); + foreach (var item in list) + { + var _list = item.GetChildDictionariesFind(DictionaryInfo); + t_Sys_Dictionaries.AddRange(_list); + } + return t_Sys_Dictionaries; + } + + public List GetDictionariesChildNode(T_Sys_DictionaryEnum dictionaryEnum) + { + return GetDictionariesChildNode(dictionaryEnum.ToString()); + } + + public T_Sys_Dictionary GetDictionaryNode(T_Sys_DictionaryEnum dictionaryEnum) + { + return DictionaryInfo.Where(it => it.ProjectCode == dictionaryEnum.ToString()).OrderBy(it => it.Sort).FirstOrDefault(); + } + } +} diff --git a/src/0-core/HuanMeng.MiaoYu.Code/SysDictionary/DictionaryNetwork/DictionaryInfoServerNetwork.cs b/src/0-core/HuanMeng.MiaoYu.Code/SysDictionary/DictionaryNetwork/DictionaryInfoServerNetwork.cs new file mode 100644 index 0000000..2d13935 --- /dev/null +++ b/src/0-core/HuanMeng.MiaoYu.Code/SysDictionary/DictionaryNetwork/DictionaryInfoServerNetwork.cs @@ -0,0 +1,156 @@ +using HuanMeng.DotNetCore.MultiTenant.Contract; +using HuanMeng.MiaoYu.Code.SysDictionary.Contract; +using HuanMeng.MiaoYu.Model.Dto; + +using Microsoft.Extensions.Configuration; + +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http.Json; +using System.Text; +using System.Threading.Tasks; + +namespace HuanMeng.MiaoYu.Code.SysDictionary.DictionaryNetwork +{ + /// + /// 字典服务 + /// + public class DictionaryInfoServerNetwork : IDictionaryInfoServer + { + private IConfiguration configuration; + private IHttpClientFactory httpClientFactory; + /// + /// 数据字典 + /// + /// + /// + public DictionaryInfoServerNetwork(IConfiguration configuration, IHttpClientFactory httpClientFactory) + + { + this.configuration = configuration; + this.httpClientFactory = httpClientFactory; + } + /// + /// + /// + //ConcurrentDictionary> Dictionarys { get; set; } + ConcurrentDictionary Dictionarys { get; set; } = new ConcurrentDictionary(); + public List GetDictionaries() + { + return Dictionarys.Values.ToList(); + } + + + public List GetDictionaries(ITenantInfo tenantInfo) + { + return Dictionarys.Values.Where(it => it.TenantId == tenantInfo.TenantId).ToList(); + + } + + public List this[ITenantInfo tenantInfo] => GetDictionaries(tenantInfo); + + /// + /// 请求地址 + /// + private string? dictionaryUrl; + /// + /// 初始化节点 + /// + /// + public async Task Initialization() + { + if (string.IsNullOrEmpty(dictionaryUrl)) + { + dictionaryUrl = configuration.GetSection("SystemConfig:DictionaryUrl").Get() ?? ""; + } + + using var client = httpClientFactory.CreateClient(); + var request = await client.GetAsync(dictionaryUrl); + if (request.IsSuccessStatusCode) + { + var json = await request.Content.ReadAsStringAsync(); + if (string.IsNullOrEmpty(json)) + { + return; + } + var jobj = JsonConvert.DeserializeObject(json); + if (jobj == null || jobj?["code"]?.ToString() != "200") + { + return; + } + var _data = jobj["data"]?.ToString(); + if (string.IsNullOrEmpty(_data)) + { + return; + } + var list = JsonConvert.DeserializeObject>(_data); + if (list == null || list.Count == 0) + { + return; + } + InitDictionary(list, null); + //查找系统节点 + var xiangmu = list.Where(it => (it.NodePath ?? "").StartsWith("huanmeng:tenant:") && it.NodeDepth == 1).ToList(); + foreach (var item in xiangmu) + { + var nodePath = item.NodePath; + //获取当前节点下的所有子节点 + var nodeList = list.Where(it => (it.NodePath ?? "").StartsWith(nodePath)).ToList(); + //初始化租户Id + var tenantIdStr = item.Value ?? ""; + if (string.IsNullOrEmpty(tenantIdStr)) + { + return; + } + if (Guid.TryParse(tenantIdStr, out var tenantId)) + { + + item.TenantId = tenantId; + //赋值 + nodeList?.ForEach(it => it.TenantId = tenantId); + } + } + //赋值数据 + ConcurrentDictionary dictionarys = new ConcurrentDictionary(); + list?.Where(it => !string.IsNullOrEmpty(it.NodePath)).ToList()?.ForEach(item => + { + dictionarys.TryAdd(item.NodePath ?? "", item); + }); + Dictionarys = dictionarys; + } + } + /// + /// 初始化数据 + /// + /// + /// + private void InitDictionary(List dictionaries, T_Sys_Dictionary? dictionary) + { + + List _dictionaries = null; + if (dictionary == null) + { + _dictionaries = dictionaries.Where(it => it.ParentId == null || it.ParentId == 0).ToList(); + } + else + { + _dictionaries = dictionaries.Where(item => item.ParentId == dictionary.Id).ToList(); + } + _dictionaries?.ForEach(it => + { + it.ParentPath = (dictionary?.NodePath ?? "huanmeng"); + it.NodePath = (dictionary?.NodePath ?? "huanmeng") + ":" + it.Code; + it.NodeDepth = (dictionary?.NodeDepth ?? -1) + 1; + + InitDictionary(dictionaries, it); + + }); + + } + } +} diff --git a/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/MiaoYuContext.cs b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/MiaoYuContext.cs index 76508eb..3dedf0a 100644 --- a/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/MiaoYuContext.cs +++ b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/MiaoYuContext.cs @@ -38,6 +38,11 @@ public partial class MiaoYuContext : MultiTenantDbContext//DbContext } + /// + /// 发现页类别菜单 + /// + public virtual DbSet T_Category_Child_Menu { get; set; } + /// /// 人物表 /// @@ -163,6 +168,36 @@ public partial class MiaoYuContext : MultiTenantDbContext//DbContext protected override void OnModelCreating(ModelBuilder modelBuilder) { + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("PK__T_Catego__3214EC07464F6CD1"); + + entity.ToTable(tb => tb.HasComment("发现页类别菜单")); + + entity.Property(e => e.ActionId) + .HasMaxLength(200) + .HasComment("动作Id"); + entity.Property(e => e.ActionType) + .HasMaxLength(200) + .HasComment("动作类型"); + entity.Property(e => e.ImageId).HasComment("图片Id"); + entity.Property(e => e.ImageUrl) + .HasMaxLength(300) + .HasComment("图片补位"); + entity.Property(e => e.Name) + .HasMaxLength(100) + .HasComment("名称"); + entity.Property(e => e.OrderById).HasComment("排序"); + entity.Property(e => e.Type) + .HasMaxLength(20) + .HasComment("菜单类型(banner,热门推荐,热门小说)"); + //添加全局筛选器 + if (this.TenantInfo != null) + { + entity.HasQueryFilter(it => it.TenantId == this.TenantInfo.TenantId); + } + }); + modelBuilder.Entity(entity => { entity.HasKey(e => e.Id).HasName("PK__T_Charac__3214EC070A8D79B3"); diff --git a/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Category_Child_Menu.cs b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Category_Child_Menu.cs new file mode 100644 index 0000000..e36a506 --- /dev/null +++ b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Category_Child_Menu.cs @@ -0,0 +1,47 @@ + +namespace HuanMeng.MiaoYu.Model.DbSqlServer.Db_MiaoYu; + +/// +/// 发现页类别菜单 +/// +public partial class T_Category_Child_Menu: MultiTenantEntity +{ + public int Id { get; set; } + + /// + /// 菜单类型(banner,热门推荐,热门小说) + /// + public string Type { get; set; } = null!; + + /// + /// 名称 + /// + public string Name { get; set; } = null!; + + /// + /// 动作Id + /// + public string ActionId { get; set; } = null!; + + /// + /// 动作类型 + /// + public string ActionType { get; set; } = null!; + + /// + /// 图片Id + /// + public int ImageId { get; set; } + + /// + /// 排序 + /// + public int OrderById { get; set; } + + /// + /// 图片补位 + /// + public string? ImageUrl { get; set; } + + public bool IsEnabled { get; set; } +} diff --git a/src/0-core/HuanMeng.MiaoYu.Model/Dto/T_Sys_Dictionary.cs b/src/0-core/HuanMeng.MiaoYu.Model/Dto/T_Sys_Dictionary.cs new file mode 100644 index 0000000..0391158 --- /dev/null +++ b/src/0-core/HuanMeng.MiaoYu.Model/Dto/T_Sys_Dictionary.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HuanMeng.MiaoYu.Model.Dto +{ + /// + /// 数据字典 + /// + public class T_Sys_Dictionary + { + /// + /// Id + /// + public int Id { get; set; } + + /// + /// 租户ID + /// + public Guid TenantId { get; set; } + + /// + /// 排序号 + /// + public int Sort { get; set; } + + /// + /// 编码 + /// + public string? Code { get; set; } + + /// + /// 分组名称/键 + /// + public string? Name { get; set; } + + /// + /// 值 + /// + public string? Value { get; set; } + + /// + /// 父级Id + /// + public int? ParentId { get; set; } + + /// + /// 扩展属性 + /// + public string? ExtendValue { get; set; } + /// + /// 项目编码 + /// + public string? ProjectCode { get; set; } + + /// + /// 路径 + /// + public string? NodePath { get; set; } + + /// + /// 当前节点路径 + /// + public string ParentPath { get; set; } + + /// + /// 节点深度 + /// + public int? NodeDepth { get; set; } + } +} diff --git a/src/0-core/HuanMeng.MiaoYu.Model/EnumModel/T_Sys_DictionaryEnum.cs b/src/0-core/HuanMeng.MiaoYu.Model/EnumModel/T_Sys_DictionaryEnum.cs new file mode 100644 index 0000000..f01653f --- /dev/null +++ b/src/0-core/HuanMeng.MiaoYu.Model/EnumModel/T_Sys_DictionaryEnum.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HuanMeng.MiaoYu.Model.EnumModel +{ + /// + /// 字典数据类型 + /// + public enum T_Sys_DictionaryEnum + { + /// + /// 项目 + /// + tenant = 0, + /// + /// 图片类型 + /// + image_types = 1, + /// + /// 菜单 + /// + categorymenu = 200, + + } +} diff --git a/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs b/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs index bbe8739..b4bba36 100644 --- a/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs +++ b/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs @@ -17,6 +17,7 @@ using HuanMeng.MiaoYu.Model.Dto; using System.Text.Json.Serialization; using HuanMeng.DotNetCore.Json; using Newtonsoft.Json.Serialization; +using HuanMeng.MiaoYu.Code.SysDictionary; var builder = WebApplication.CreateBuilder(args); //Log.Logger = new LoggerConfiguration() // .WriteTo.Console() @@ -115,6 +116,8 @@ builder.AddTencent(); builder.AddMemoryVerificationCode(); //添加jwt验证 builder.AddJwtConfig(); +//添加数据字典 +builder.AddDictionaryInfo(); //builder.Services.AddMemoryCache(); //builder.Services.AddScoped(); ////builder.Services.AddScoped(); diff --git a/src/2-api/HuanMeng.MiaoYu.WebApi/appsettings.json b/src/2-api/HuanMeng.MiaoYu.WebApi/appsettings.json index 59fdcf1..6650f1f 100644 --- a/src/2-api/HuanMeng.MiaoYu.WebApi/appsettings.json +++ b/src/2-api/HuanMeng.MiaoYu.WebApi/appsettings.json @@ -60,6 +60,9 @@ }, "AllowedHosts": "*", + "SystemConfig": { + "DictionaryUrl": "https://adminapi.shhuanmeng.com/api/v1/admin/SysDictionary/GetList" + }, //服务器配置 "Kestrel": { "Endpoints": {