diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Base/MiaoYuBase.cs b/src/0-core/HuanMeng.MiaoYu.Code/Base/MiaoYuBase.cs index 991f921..ad3b19b 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/Base/MiaoYuBase.cs +++ b/src/0-core/HuanMeng.MiaoYu.Code/Base/MiaoYuBase.cs @@ -84,7 +84,7 @@ namespace HuanMeng.MiaoYu.Code.Base { get { - if (_mapper == null) + if (_HttpContextAccessor == null) { _HttpContextAccessor = _serviceProvider.GetRequiredService(); } @@ -184,25 +184,31 @@ namespace HuanMeng.MiaoYu.Code.Base var accessToken = HttpContextAccessor.HttpContext.GetTokenAsync("Bearer", "access_token").Result; if (string.IsNullOrEmpty(accessToken)) { - + _userInfo = new RequestUserInfo() + { + UserId = 0 + }; } - var (principal, jwtToken) = JwtAuthManager.DecodeJwtToken(accessToken); - if (jwtToken == null || !jwtToken.Header.Alg.Equals(SecurityAlgorithms.HmacSha256Signature)) + else { - throw new SecurityTokenException("无效的token"); + var (principal, jwtToken) = JwtAuthManager.DecodeJwtToken(accessToken); + if (jwtToken == null || !jwtToken.Header.Alg.Equals(SecurityAlgorithms.HmacSha256Signature)) + { + throw new SecurityTokenException("无效的token"); + } + var userIdStr = principal.FindFirst("UserId")?.Value; + if (string.IsNullOrEmpty(userIdStr)) + { + throw new SecurityTokenException("无效的token"); + } + var nickName = principal.FindFirst("NickName")?.Value; + var userId = int.Parse(userIdStr); + _userInfo = new RequestUserInfo() + { + UserId = userId, + NickName = nickName + }; } - var userIdStr = principal.FindFirst("UserId")?.Value; - if (string.IsNullOrEmpty(userIdStr)) - { - throw new SecurityTokenException("无效的token"); - } - var nickName = principal.FindFirst("NickName")?.Value; - var userId = int.Parse(userIdStr); - _userInfo = new RequestUserInfo() - { - UserId = userId, - NickName = nickName - }; } return _userInfo; } @@ -221,7 +227,7 @@ namespace HuanMeng.MiaoYu.Code.Base #endregion #region 缓存实现类 - private MiaoYuCache? _miaoYuCache ; //new MiaoYuCache(Dao, Mapper); + private MiaoYuCache? _miaoYuCache; //new MiaoYuCache(Dao, Mapper); /// /// 妙语实现类 /// diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Cache/CommonDataEntityCache.cs b/src/0-core/HuanMeng.MiaoYu.Code/Cache/CommonDataEntityCache.cs index 2a22092..86fb00d 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/Cache/CommonDataEntityCache.cs +++ b/src/0-core/HuanMeng.MiaoYu.Code/Cache/CommonDataEntityCache.cs @@ -1,5 +1,7 @@ using Microsoft.EntityFrameworkCore; +using Newtonsoft.Json; + using System; using System.Collections.Generic; using System.Linq; @@ -34,19 +36,19 @@ namespace HuanMeng.MiaoYu.Code.Cache { if (_dataList == null) { - - _dataList = MemoryCacheHelper.GetCache>(key); - if (_dataList == null) + var tempDataList = MemoryCacheHelper.GetCache>(key); + if (tempDataList == null) { lock (lockObj) { - if (_dataList == null) + if (tempDataList == null) { - _dataList = GetDataList(); - MemoryCacheHelper.SetCache(key, _dataList, cacheTime); + tempDataList = GetDataList(); + MemoryCacheHelper.SetCache(key, tempDataList, cacheTime); } } } + _dataList = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(tempDataList)); } return _dataList ?? new List(); } diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Cache/MiaoYuCache.cs b/src/0-core/HuanMeng.MiaoYu.Code/Cache/MiaoYuCache.cs index 27128cc..9560e76 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/Cache/MiaoYuCache.cs +++ b/src/0-core/HuanMeng.MiaoYu.Code/Cache/MiaoYuCache.cs @@ -81,11 +81,39 @@ namespace HuanMeng.MiaoYu.Code.Cache { if (CharacterCache == null) { + CharacterCache = new CharacterEntityCache(dao, mapper); } return CharacterCache.DataList ?? new List(); } } #endregion + + #region 图片缓存表 + /// + /// 图片缓存表 + /// + private static object ImageConfigLock = new object(); + + /// + /// 图片缓存表 + /// + public MiaoYuDataEntityCache? ImageConfigCache { get; set; } + /// + /// 图片 + /// + public List ImageConfigList + { + get + { + if (ImageConfigCache == null) + { + ImageConfigCache = new MiaoYuDataEntityCache(dao, ImageConfigLock); + } + return ImageConfigCache.DataList ?? new List(); + } + } + + #endregion } } diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Cache/Special/CharacterEntityCache.cs b/src/0-core/HuanMeng.MiaoYu.Code/Cache/Special/CharacterEntityCache.cs index 802ef29..d19b428 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/Cache/Special/CharacterEntityCache.cs +++ b/src/0-core/HuanMeng.MiaoYu.Code/Cache/Special/CharacterEntityCache.cs @@ -1,7 +1,9 @@ using AutoMapper; using HuanMeng.MiaoYu.Code.DataAccess; +using HuanMeng.MiaoYu.Code.Other; using HuanMeng.MiaoYu.Model.Dto.Character; +using HuanMeng.MiaoYu.Model.Dto.Label; using System; using System.Collections.Generic; @@ -21,37 +23,69 @@ namespace HuanMeng.MiaoYu.Code.Cache.Special /// 锁 /// private static object CharacterCacheLock = new object(); - + private static object ImageLock = new object(); + private static object T_Character_LabelLock = new object(); + private static object T_Character_Label_RelationLock = new object(); /// /// 获取缓存数据 /// /// public override List GetDataList() { - List characterCaches = null; + List characterCaches = new List(); //读取角色表 var characters = _dao.daoDbMiaoYu.context.T_Character.ToList(); if (characters == null) { - return new List(); + return characterCaches; } characterCaches = mapper.Map>(characters); + string sqlString = $"select TOP 100 CharacterId,count(DISTINCT UserId ) UserCount from T_User_Char where isdelete=0 and TenantId='{_dao.daoDbMiaoYu.context.TenantInfo?.TenantId}' GROUP BY CharacterId"; + //获取查看次数 + var characteChatCounts = _dao.daoDbMiaoYu.SqlQueryList(sqlString); //查询配置表 var modelConfigs = _dao.daoDbMiaoYu.context.T_Model_Config.ToList(); + var ImageConfigCache = new MiaoYuDataEntityCache(_dao, ImageLock); + var images = ImageConfigCache.DataList; + //标签 + var labelCache = new MiaoYuDataEntityCache(_dao, T_Character_LabelLock); + var labels = labelCache.DataList; + var labelRelationCache = new MiaoYuDataEntityCache(_dao, T_Character_Label_RelationLock); + var labelRelations = labelRelationCache.DataList; + foreach (var characterCache in characterCaches) { var modelConfig = modelConfigs.FirstOrDefault(it => it.Id == characterCache.ModelConfigId); if (modelConfig != null) { characterCache.ModelConfig = modelConfig; + //查询图片 + characterCache.IconImage = images.GetImageUrl(characterCache.IconImg ?? 0); + characterCache.BgImage = images.GetImageUrl(characterCache.BgImg ?? 0); + var c = characteChatCounts.FirstOrDefault(it => it.CharacterId == characterCache.Id); + if (c != null) + { + characterCache.LookCount = c.UserCount; + } + var characterLabelIds = labelRelations.Where(it => it.CharacterId == characterCache.Id).Select(it => it.CharacterLabelId).ToList(); + if (characterLabelIds.Count > 0) + { + var lab = labels.Where(it => characterLabelIds.Contains(it.Id)).ToList(); + var labs = mapper.Map>(lab); + characterCache.Label = labs; + } + else + { + characterCache.Label = new List(); + } } + } //移除没有配置模型的类 characterCaches.Where(it => it.ModelConfig == null).ToList().ForEach(characterCache => { characterCaches.Remove(characterCache); }); - return characterCaches; } } diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Character/CharacterBLL.cs b/src/0-core/HuanMeng.MiaoYu.Code/Character/CharacterBLL.cs index 18ab0e3..f46f005 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/Character/CharacterBLL.cs +++ b/src/0-core/HuanMeng.MiaoYu.Code/Character/CharacterBLL.cs @@ -1,3 +1,13 @@ + + +using AutoMapper; + +using HuanMeng.DotNetCore.Base; +using HuanMeng.MiaoYu.Model.Dto.Character; +using HuanMeng.MiaoYu.Model.Dto.Chat; + +using Microsoft.EntityFrameworkCore; + using System; using System.Collections.Generic; using System.Linq; @@ -16,20 +26,74 @@ namespace HuanMeng.MiaoYu.Code.Character } /// - /// + /// 首页获取角色列表 /// /// - public Task GetCharacter(int index) + public async Task>> GetHomeCharacter(RequestCharacterInfoPage requestCharacterInfo) { - - var charactersList = MiaoYuCache.CharactersList.Where(it => it.Visibility).ToList(); + var index = requestCharacterInfo.Index ?? 0; + var size = requestCharacterInfo.Size ?? 10; + var charactersList = MiaoYuCache.CharacterList.OrderByDescending(it => it.LookCount) + .Skip((index - 1) * size).Take(size).ToList(); if (charactersList.Count == 0) { - return null; + return new BaseResponse>(); } - - return null; + var list = Mapper.Map>(charactersList); + //不是游客 + if (_UserId != 0) + { + List characterIds = list.Select(it => it.CharacterId).ToList(); + //获取亲密值 + var intimacys = await Dao.daoDbMiaoYu.context.T_Character_User_Intimacy.Where(it => it.UserId == _UserId + && characterIds.Contains(it.CharacterId)).ToListAsync(); + list.ForEach(it => + { + it.Intimacy = intimacys.FirstOrDefault(item => item.CharacterId == it.CharacterId)?.IntimacyValue ?? 0; + }); + } + return new BaseResponse>(ResonseCode.Success, "", list); } + + + /// + /// 获取角色详情 + /// + /// + /// + public async Task> GetCharacterInfo(RequestCharacterInfo requestCharacterInfo) + { + var charactersinfo = MiaoYuCache.CharacterList.FirstOrDefault(it => it.Id == requestCharacterInfo.CharacterId); + if (charactersinfo == null) + { + return new BaseResponse(); + } + var info = Mapper.Map(charactersinfo); + //不是游客 + if (_UserId != 0) + { + //获取亲密值 + var intimacys = await Dao.daoDbMiaoYu.context.T_Character_User_Intimacy.Where(it => it.UserId == _UserId + && it.CharacterId == info.CharacterId).FirstOrDefaultAsync(); + info.Intimacy = intimacys?.IntimacyValue ?? 0; + } + return new BaseResponse(ResonseCode.Success, "", info); + } + + /// + /// 获取全部角色的Id + /// + /// + public BaseResponse> GetCharacters() + { + Random rng = new Random(); + var charactersIds = MiaoYuCache.CharacterList.Select(it => it.Id).OrderBy(x => rng.Next()).ToList(); + if (charactersIds == null) + { + charactersIds = new List(); + } + return new BaseResponse>(ResonseCode.Success, "", charactersIds); + } } } diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Chat/ChatBLL.cs b/src/0-core/HuanMeng.MiaoYu.Code/Chat/ChatBLL.cs index ecfc17a..b22841e 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/Chat/ChatBLL.cs +++ b/src/0-core/HuanMeng.MiaoYu.Code/Chat/ChatBLL.cs @@ -1,7 +1,7 @@ using HuanMeng.DotNetCore.Base; using HuanMeng.MiaoYu.Code.Cache; using HuanMeng.MiaoYu.Model.DbSqlServer.Db_MiaoYu; -using HuanMeng.MiaoYu.Model.Dto.Home; + using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Other/ImageExtend.cs b/src/0-core/HuanMeng.MiaoYu.Code/Other/ImageExtend.cs new file mode 100644 index 0000000..0fe4f3d --- /dev/null +++ b/src/0-core/HuanMeng.MiaoYu.Code/Other/ImageExtend.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HuanMeng.MiaoYu.Code.Other +{ + /// + /// 图片扩展类 + /// + public static class ImageExtend + { + /// + /// 获取图片地址 + /// + /// + /// + /// + public static string GetImageUrl(this List configs, int imageId) + { + if (imageId > 0 && configs != null && configs.Count > 0) + { + return configs.FirstOrDefault(it => it.ImageId == imageId)?.Url ?? ""; + } + return ""; + } + } +} 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 70593d5..95dadef 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 @@ -180,12 +180,8 @@ public partial class MiaoYuContext : MultiTenantDbContext//DbContext entity.ToTable(tb => tb.HasComment("关联角色和标签")); - entity.Property(e => e.Id) - .ValueGeneratedNever() - .HasComment("人物和标签的关联id"); - entity.Property(e => e.CharacterId_) - .HasComment("人物Id") - .HasColumnName("CharacterId "); + entity.Property(e => e.Id).HasComment("人物和标签的关联id"); + entity.Property(e => e.CharacterId).HasComment("人物Id"); entity.Property(e => e.CharacterLabelId).HasComment("人物标签id"); entity.Property(e => e.CreateTime) .HasComment("创建时间") @@ -210,12 +206,16 @@ public partial class MiaoYuContext : MultiTenantDbContext//DbContext entity.Property(e => e.Id) .ValueGeneratedNever() .HasComment("类型id"); - entity.Property(e => e.CreateTime).HasComment("创建时间"); + entity.Property(e => e.CreateTime) + .HasComment("创建时间") + .HasColumnType("datetime"); entity.Property(e => e.Name) .HasMaxLength(255) .HasComment("类型名称"); entity.Property(e => e.TenantId).HasComment("租户id"); - entity.Property(e => e.UpdateTime).HasComment("更新时间"); + entity.Property(e => e.UpdateTime) + .HasComment("更新时间") + .HasColumnType("datetime"); //添加全局筛选器 if (this.TenantInfo != null) { @@ -229,9 +229,7 @@ public partial class MiaoYuContext : MultiTenantDbContext//DbContext entity.ToTable(tb => tb.HasComment("存储用户和角色之间的亲密值")); - entity.Property(e => e.Id) - .ValueGeneratedNever() - .HasComment("亲密度id"); + entity.Property(e => e.Id).HasComment("亲密度id"); entity.Property(e => e.CharacterId).HasComment("人物Id"); entity.Property(e => e.CreateTime) .HasComment("创建时间") diff --git a/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Character_Label_Relation.cs b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Character_Label_Relation.cs index 91e1ed3..0b68be0 100644 --- a/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Character_Label_Relation.cs +++ b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Character_Label_Relation.cs @@ -12,24 +12,24 @@ public partial class T_Character_Label_Relation: MultiTenantEntity /// public int Id { get; set; } + /// /// 人物Id /// - public int? CharacterId_ { get; set; } + public int CharacterId { get; set; } /// /// 人物标签id /// - public int? CharacterLabelId { get; set; } + public int CharacterLabelId { get; set; } /// /// 创建时间 /// - public DateTime? CreateTime { get; set; } + public DateTime CreateTime { get; set; } /// /// 更新时间 /// - public DateTime? UpdateTime { get; set; } - + public DateTime UpdateTime { get; set; } } diff --git a/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Character_Type.cs b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Character_Type.cs index fd0d9dc..13fb246 100644 --- a/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Character_Type.cs +++ b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Character_Type.cs @@ -15,8 +15,7 @@ public partial class T_Character_Type: MultiTenantEntity /// /// 类型名称 /// - public string? Name { get; set; } - + public string Name { get; set; } = null!; /// /// 创建时间 @@ -27,4 +26,5 @@ public partial class T_Character_Type: MultiTenantEntity /// 更新时间 /// public DateTime UpdateTime { get; set; } + } diff --git a/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Character_User_Intimacy.cs b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Character_User_Intimacy.cs index 17579eb..71686a3 100644 --- a/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Character_User_Intimacy.cs +++ b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Character_User_Intimacy.cs @@ -16,25 +16,25 @@ public partial class T_Character_User_Intimacy: MultiTenantEntity /// /// 人物Id /// - public int? CharacterId { get; set; } + public int CharacterId { get; set; } /// /// 用户Id /// - public int? UserId { get; set; } + public int UserId { get; set; } /// /// 亲密值 /// - public int? IntimacyValue { get; set; } + public int IntimacyValue { get; set; } /// /// 创建时间 /// - public DateTime? CreateTime { get; set; } + public DateTime CreateTime { get; set; } /// /// 更新时间 /// - public DateTime? UpdateTime { get; set; } + public DateTime UpdateTime { get; set; } } diff --git a/src/0-core/HuanMeng.MiaoYu.Model/Dto/Character/CharacteChatCountModel.cs b/src/0-core/HuanMeng.MiaoYu.Model/Dto/Character/CharacteChatCountModel.cs new file mode 100644 index 0000000..dfe66e2 --- /dev/null +++ b/src/0-core/HuanMeng.MiaoYu.Model/Dto/Character/CharacteChatCountModel.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HuanMeng.MiaoYu.Model.Dto.Character +{ + /// + /// 角色聊天次数 + /// + public class CharacteChatCountModel + { + /// + /// 角色Id + /// + public int CharacterId { get; set; } + + /// + /// 聊天次数 + /// + public int UserCount { get; set; } + } +} diff --git a/src/0-core/HuanMeng.MiaoYu.Model/Dto/Character/CharacterCache.cs b/src/0-core/HuanMeng.MiaoYu.Model/Dto/Character/CharacterCache.cs index e8e1996..93c7b88 100644 --- a/src/0-core/HuanMeng.MiaoYu.Model/Dto/Character/CharacterCache.cs +++ b/src/0-core/HuanMeng.MiaoYu.Model/Dto/Character/CharacterCache.cs @@ -1,6 +1,7 @@ using AutoMapper; using HuanMeng.MiaoYu.Model.DbSqlServer.Db_MiaoYu; +using HuanMeng.MiaoYu.Model.Dto.Label; using System; using System.Collections.Generic; @@ -25,5 +26,20 @@ namespace HuanMeng.MiaoYu.Model.Dto.Character /// 多少人聊天过 /// public int LookCount { get; set; } + + /// + /// 背景图片 + /// + public string BgImage { get; set; } + + /// + /// 用户头像url + /// + public string IconImage { get; set; } + + /// + /// 标签 + /// + public List Label { get; set; } } } diff --git a/src/0-core/HuanMeng.MiaoYu.Model/Dto/Character/RequestCharacterInfo.cs b/src/0-core/HuanMeng.MiaoYu.Model/Dto/Character/RequestCharacterInfo.cs new file mode 100644 index 0000000..d5138a6 --- /dev/null +++ b/src/0-core/HuanMeng.MiaoYu.Model/Dto/Character/RequestCharacterInfo.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HuanMeng.MiaoYu.Model.Dto.Character +{ + /// + /// + /// + public class RequestCharacterInfo + { + /// + /// 角色Id + /// + public int CharacterId { get; set; } + } +} diff --git a/src/0-core/HuanMeng.MiaoYu.Model/Dto/Character/RequestCharacterInfoPage.cs b/src/0-core/HuanMeng.MiaoYu.Model/Dto/Character/RequestCharacterInfoPage.cs new file mode 100644 index 0000000..80bc5f5 --- /dev/null +++ b/src/0-core/HuanMeng.MiaoYu.Model/Dto/Character/RequestCharacterInfoPage.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HuanMeng.MiaoYu.Model.Dto.Character +{ + /// + /// 请求参数 + /// + public class RequestCharacterInfoPage + { + /// + /// 起始页 + /// + public int? Index { get; set; } = 1; + + /// + /// 页大小 + /// + public int? Size { get; set; } = 10; + } + +} + + diff --git a/src/0-core/HuanMeng.MiaoYu.Model/Dto/Chat/CharacterInfoDto.cs b/src/0-core/HuanMeng.MiaoYu.Model/Dto/Chat/CharacterInfoDto.cs index b125dd6..3d00b63 100644 --- a/src/0-core/HuanMeng.MiaoYu.Model/Dto/Chat/CharacterInfoDto.cs +++ b/src/0-core/HuanMeng.MiaoYu.Model/Dto/Chat/CharacterInfoDto.cs @@ -1,10 +1,16 @@ +using AutoMapper; +using AutoMapper.Configuration.Annotations; + +using HuanMeng.MiaoYu.Model.Dto.Character; +using HuanMeng.MiaoYu.Model.Dto.Label; + using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace HuanMeng.MiaoYu.Model.Dto.Home +namespace HuanMeng.MiaoYu.Model.Dto.Chat { public class CharacterInfo { @@ -13,11 +19,13 @@ namespace HuanMeng.MiaoYu.Model.Dto.Home /// /// 用户和人物信息 /// + [AutoMap(typeof(CharacterCache))] public class CharacterInfoDto { /// /// 头像 /// + [SourceMember(nameof(CharacterCache.IconImage))] public string Icon { get; set; } /// @@ -28,16 +36,19 @@ namespace HuanMeng.MiaoYu.Model.Dto.Home /// /// 人物id /// + [SourceMember(nameof(CharacterCache.Id))] public int CharacterId { get; set; } /// /// 人物名称 /// + [SourceMember(nameof(CharacterCache.Name))] public string CharacterName { get; set; } /// /// 性别 /// + public int Gender { get; set; } /// @@ -48,11 +59,13 @@ namespace HuanMeng.MiaoYu.Model.Dto.Home /// /// 背景图片 /// + [SourceMember(nameof(CharacterCache.BgImage))] public string BgUrl { get; set; } /// /// 简介 /// + public string Biography { get; set; } /// @@ -63,6 +76,7 @@ namespace HuanMeng.MiaoYu.Model.Dto.Home /// /// 标签 /// + [SourceMember(nameof(CharacterCache.Label))] public List Label { get; set; } /// @@ -128,7 +142,7 @@ namespace HuanMeng.MiaoYu.Model.Dto.Home /// /// 人物id /// - public int CharacterId { get; set; } + public int CharacterId { get; set; } } /// diff --git a/src/0-core/HuanMeng.MiaoYu.Model/Dto/Label/LabelDto.cs b/src/0-core/HuanMeng.MiaoYu.Model/Dto/Label/LabelDto.cs new file mode 100644 index 0000000..1fd69d0 --- /dev/null +++ b/src/0-core/HuanMeng.MiaoYu.Model/Dto/Label/LabelDto.cs @@ -0,0 +1,32 @@ +using AutoMapper; +using AutoMapper.Configuration.Annotations; + +using HuanMeng.MiaoYu.Model.DbSqlServer.Db_MiaoYu; +using HuanMeng.MiaoYu.Model.Dto.Character; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HuanMeng.MiaoYu.Model.Dto.Label +{ + + /// + /// 人物角色标签 + /// + [AutoMap(typeof(T_Character_Label))] + public class LabelDto + { + /// + /// + /// + public int Id { get; set; } + /// + /// 标签名称 + /// + [SourceMember(nameof(T_Character_Label.LabelName))] + public string Name { get; set; } + } +} diff --git a/src/0-core/HuanMeng.MiaoYu.Model/HuanMeng.MiaoYu.Model.csproj b/src/0-core/HuanMeng.MiaoYu.Model/HuanMeng.MiaoYu.Model.csproj index 8e75674..a36070f 100644 --- a/src/0-core/HuanMeng.MiaoYu.Model/HuanMeng.MiaoYu.Model.csproj +++ b/src/0-core/HuanMeng.MiaoYu.Model/HuanMeng.MiaoYu.Model.csproj @@ -5,6 +5,7 @@ enable enable True + latest diff --git a/src/2-api/HuanMeng.MiaoYu.WebApi/Controllers/ChatController.cs b/src/2-api/HuanMeng.MiaoYu.WebApi/Controllers/ChatController.cs index 0d00824..33ecf68 100644 --- a/src/2-api/HuanMeng.MiaoYu.WebApi/Controllers/ChatController.cs +++ b/src/2-api/HuanMeng.MiaoYu.WebApi/Controllers/ChatController.cs @@ -1,6 +1,8 @@ using HuanMeng.DotNetCore.Base; +using HuanMeng.MiaoYu.Code.Character; using HuanMeng.MiaoYu.Code.Chat; -using HuanMeng.MiaoYu.Model.Dto.Home; +using HuanMeng.MiaoYu.Model.Dto.Character; +using HuanMeng.MiaoYu.Model.Dto.Chat; using HuanMeng.MiaoYu.WebApi.Base; using Microsoft.AspNetCore.Authorization; @@ -29,15 +31,33 @@ namespace HuanMeng.MiaoYu.WebApi.Controllers } /// - /// 获取人物信息 + /// 获取角色Id /// /// [HttpGet] [AllowAnonymous] - public async Task>> GetCharacterInfo() + public BaseResponse> GetCharacterIdList() { + CharacterBLL characterBLL = new CharacterBLL(ServiceProvider); + var obj = characterBLL.GetCharacters(); + return obj; - var obj = JsonConvert.DeserializeObject>("[{\"Icon\":\"\",\"Intimacy\":10,\"CharacterId\":2,\"CharacterName\":\"许荷姻\",\"Gender\":1,\"LookCount\":2,\"BgUrl\":\"\",\"Biography\":\"你那商业联姻得来的妻子,原本的天才女孩,聪明伶俐,生的漂亮、端庄,不知贵圈多少人梦寐以求的存在。\",\"Prologue\":\"坐在轮椅上,眼神平静的看着你,语气也同样平静)你回来了。饭菜在桌上,我刚刚热了。(说到这,又垂下眸子道)我还做了碗醒酒汤,记得喝\",\"Label\":[{\"LabelId\":1,\"LabelName\":\"美女\"},{\"LabelId\":2,\"LabelName\":\"二次元\"}],\"RemainingChatCount\":1}]"); + } + + + /// + /// 获取角色人物信息 + /// + /// + [HttpGet] + [AllowAnonymous] + public async Task> GetCharacterInfo([FromQuery] RequestCharacterInfo requestCharacterInfo) + { + CharacterBLL characterBLL = new CharacterBLL(ServiceProvider); + var obj = await characterBLL.GetCharacterInfo(requestCharacterInfo); + return obj; + + var obj = JsonConvert.DeserializeObject>("[{\"Icon\":\"\",\"Intimacy\":10,\"CharacterId\":2,\"CharacterName\":\"许荷姻\",\"Gender\":1,\"LookCount\":2,\"BgUrl\":\"\",\"Biography\":\"你那商业联姻得来的妻子,原本的天才女孩,聪明伶俐,生的漂亮、端庄,不知贵圈多少人梦寐以求的存在。\",\"Prologue\":\"坐在轮椅上,眼神平静的看着你,语气也同样平静)你回来了。饭菜在桌上,我刚刚热了。(说到这,又垂下眸子道)我还做了碗醒酒汤,记得喝\",\"Label\":[{\"Id\":1,\"Name\":\"美女\"},{\"Id\":2,\"Name\":\"二次元\"}],\"RemainingChatCount\":1}]"); return new BaseResponse>(ResonseCode.Success, "", obj); } diff --git a/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs b/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs index ca91066..5f71777 100644 --- a/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs +++ b/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs @@ -13,6 +13,7 @@ using HuanMeng.DotNetCore.CustomExtension; using HuanMeng.MiaoYu.Code.Cache; using HuanMeng.MiaoYu.Code.Chat; using Serilog; +using HuanMeng.MiaoYu.Model.Dto; var builder = WebApplication.CreateBuilder(args); //Log.Logger = new LoggerConfiguration() // .WriteTo.Console() @@ -30,7 +31,20 @@ builder.Services.AddHttpContextAccessor(); //添加httpContext注入访问 var _myAllowSpecificOrigins = "_myAllowSpecificOrigins"; builder.Services.AddCustomCors(_myAllowSpecificOrigins); #endregion -builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies().Where(it => it.FullName.Contains("HuanMeng") || it.FullName.Contains("XLib.")).ToList()); +#region automap +var mapperDomain = AppDomain.CurrentDomain.GetAssemblies().Where(it => it.FullName.Contains("HuanMeng") || it.FullName.Contains("XLib.")).ToList(); +Type type = typeof(ResponseUserInfo); +if (type != null) +{ + Assembly assembly = Assembly.GetAssembly(type); + if (!mapperDomain.Any(it => it.FullName == assembly.FullName)) + { + mapperDomain.Add(assembly); + } +} + +builder.Services.AddAutoMapper(mapperDomain); +#endregion builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); @@ -72,7 +86,7 @@ builder.Services.AddSwaggerGen(c => c.RequestBodyFilter(); }); //配置路由选项,使URL全部小写 -builder.Services.AddRouting(options => options.LowercaseUrls = true); +//builder.Services.AddRouting(options => options.LowercaseUrls = true); //添加多租户 builder.AddMultiTenantMiaoYu(); //添加腾讯云管理