From 03710a37b1c8bac37086edd4bd3f64a452b2d455 Mon Sep 17 00:00:00 2001 From: bibabo <765221495@qq.com> Date: Fri, 12 Jul 2024 16:41:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=81=8A=E5=A4=A9=E8=AE=B0?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HuanMeng.MiaoYu.Code/Chat/ChatBLL.cs | 38 +++ .../DbSqlServer/Db_MiaoYu/MiaoYuContext.cs | 217 ++++++++++++++++++ .../DbSqlServer/Db_MiaoYu/T_Character.cs | 65 ++++++ .../Db_MiaoYu/T_Character_Label.cs | 30 +++ .../Db_MiaoYu/T_Character_Label_Relation.cs | 35 +++ .../DbSqlServer/Db_MiaoYu/T_Character_Type.cs | 30 +++ .../Db_MiaoYu/T_Character_User_Intimacy.cs | 40 ++++ .../DbSqlServer/Db_MiaoYu/T_Chat.cs | 75 ++++++ .../Controllers/ChatController.cs | 25 +- 9 files changed, 551 insertions(+), 4 deletions(-) create mode 100644 src/0-core/HuanMeng.MiaoYu.Code/Chat/ChatBLL.cs create mode 100644 src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Character.cs create mode 100644 src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Character_Label.cs create mode 100644 src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Character_Label_Relation.cs create mode 100644 src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Character_Type.cs create mode 100644 src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Character_User_Intimacy.cs create mode 100644 src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Chat.cs diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Chat/ChatBLL.cs b/src/0-core/HuanMeng.MiaoYu.Code/Chat/ChatBLL.cs new file mode 100644 index 0000000..2416718 --- /dev/null +++ b/src/0-core/HuanMeng.MiaoYu.Code/Chat/ChatBLL.cs @@ -0,0 +1,38 @@ +using HuanMeng.DotNetCore.Base; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HuanMeng.MiaoYu.Code.Chat +{ + /// + /// 聊天类 + /// + public class ChatBLL : MiaoYuBase + { + public ChatBLL(IServiceProvider serviceProvider) : base(serviceProvider) + { + + } + /// + /// 删除聊天记录 + /// + /// 聊天id + /// + /// + public async Task DelChatByIds(List id,int characterId) + { + var chatsToDelete = Dao.daoDbMiaoYu.context.T_Chat.Where(t => id.Contains(t.Id)).ToList(); + if (chatsToDelete.Count <= 0) + { + throw new Exception(""); + } + var chatList = chatsToDelete.Where(t => t.UserId == _UserId && t.CharacterId == characterId && t.IsDel == false).ToList(); + Dao.daoDbMiaoYu.context.T_Chat.RemoveRange(chatList); + Dao.daoDbMiaoYu.context.SaveChanges(); + return true; + } + } +} 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 363d32d..f26e777 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,36 @@ public partial class MiaoYuContext : MultiTenantDbContext//DbContext } + /// + /// 人物表 + /// + public virtual DbSet T_Character { get; set; } + + /// + /// 角色标签表 + /// + public virtual DbSet T_Character_Label { get; set; } + + /// + /// 关联角色和标签 + /// + public virtual DbSet T_Character_Label_Relation { get; set; } + + /// + /// 发现页类型分类 + /// + public virtual DbSet T_Character_Type { get; set; } + + /// + /// 存储用户和角色之间的亲密值 + /// + public virtual DbSet T_Character_User_Intimacy { get; set; } + + /// + /// 聊天记录表 + /// + public virtual DbSet T_Chat { get; set; } + /// /// 用户表 /// @@ -63,6 +93,193 @@ public partial class MiaoYuContext : MultiTenantDbContext//DbContext protected override void OnModelCreating(ModelBuilder modelBuilder) { + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("PK__T_Charac__3214EC070A8D79B3"); + + entity.ToTable(tb => tb.HasComment("人物表")); + + entity.Property(e => e.Id) + .ValueGeneratedNever() + .HasComment("人物id"); + entity.Property(e => e.Biography) + .HasMaxLength(500) + .HasComment("人物简介"); + entity.Property(e => e.CreateTime) + .HasComment("创建时间") + .HasColumnType("datetime"); + entity.Property(e => e.Gender).HasComment("性别0男1女2其他"); + entity.Property(e => e.Model) + .HasMaxLength(255) + .IsUnicode(false) + .HasComment("人物模型"); + entity.Property(e => e.Name) + .HasMaxLength(50) + .HasComment("人物名字"); + entity.Property(e => e.Prologue) + .HasMaxLength(255) + .HasComment("开场白"); + entity.Property(e => e.Style).HasComment("风格id"); + entity.Property(e => e.System) + .HasMaxLength(255) + .IsUnicode(false) + .HasComment("人物初始设定"); + entity.Property(e => e.TenantId).HasComment("租户Id"); + entity.Property(e => e.UpdateTime) + .HasComment("更新时间") + .HasColumnType("datetime"); + entity.Property(e => e.Visibility).HasComment("公开/私密 0公开 1私密"); + //添加全局筛选器 + if (this.TenantInfo != null) + { + entity.HasQueryFilter(it => it.TenantId == this.TenantInfo.TenantId); + } + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("PK__T_Charac__3214EC0777B5F217"); + + entity.ToTable(tb => tb.HasComment("角色标签表")); + + entity.Property(e => e.Id) + .ValueGeneratedNever() + .HasComment("标签id"); + entity.Property(e => e.CreateTime) + .HasComment("创建时间") + .HasColumnType("datetime"); + entity.Property(e => e.LabelName) + .HasMaxLength(50) + .HasComment("标签名称"); + entity.Property(e => e.TenantId).HasComment("租户id"); + entity.Property(e => e.UpdateTime) + .HasComment("更新时间") + .HasColumnType("datetime"); + //添加全局筛选器 + if (this.TenantInfo != null) + { + entity.HasQueryFilter(it => it.TenantId == this.TenantInfo.TenantId); + } + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("PK__T_Charac__3214EC071FC16A53"); + + 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.CharacterLabelId).HasComment("人物标签id"); + entity.Property(e => e.CreateTime) + .HasComment("创建时间") + .HasColumnType("datetime"); + entity.Property(e => e.TenantId).HasComment("租户id"); + entity.Property(e => e.UpdateTime) + .HasComment("更新时间") + .HasColumnType("datetime"); + //添加全局筛选器 + if (this.TenantInfo != null) + { + entity.HasQueryFilter(it => it.TenantId == this.TenantInfo.TenantId); + } + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("PK__T_Charac__3214EC070CC04F82"); + + entity.ToTable(tb => tb.HasComment("发现页类型分类")); + + entity.Property(e => e.Id) + .ValueGeneratedNever() + .HasComment("类型id"); + entity.Property(e => e.CreateTime).HasComment("创建时间"); + entity.Property(e => e.Name) + .HasMaxLength(255) + .HasComment("类型名称"); + entity.Property(e => e.TenantId).HasComment("租户id"); + entity.Property(e => e.UpdateTime).HasComment("更新时间"); + //添加全局筛选器 + if (this.TenantInfo != null) + { + entity.HasQueryFilter(it => it.TenantId == this.TenantInfo.TenantId); + } + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("PK__T_Charac__3214EC079BEEBDEA"); + + entity.ToTable(tb => tb.HasComment("存储用户和角色之间的亲密值")); + + entity.Property(e => e.Id) + .ValueGeneratedNever() + .HasComment("亲密度id"); + entity.Property(e => e.CharacterId).HasComment("人物Id"); + entity.Property(e => e.CreateTime) + .HasComment("创建时间") + .HasColumnType("datetime"); + entity.Property(e => e.IntimacyValue).HasComment("亲密值"); + entity.Property(e => e.TenantId).HasComment("租户id"); + entity.Property(e => e.UpdateTime) + .HasComment("更新时间") + .HasColumnType("datetime"); + entity.Property(e => e.UserId).HasComment("用户Id"); + //添加全局筛选器 + if (this.TenantInfo != null) + { + entity.HasQueryFilter(it => it.TenantId == this.TenantInfo.TenantId); + } + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("PK__T_Chat__3214EC079C2C8859"); + + entity.ToTable(tb => tb.HasComment("聊天记录表")); + + entity.Property(e => e.Id) + .ValueGeneratedNever() + .HasComment("聊天id"); + entity.Property(e => e.CharacterId).HasComment("人物表Id"); + entity.Property(e => e.Content) + .HasMaxLength(255) + .HasComment("消息内容"); + entity.Property(e => e.CreateDay).HasComment("发送日期"); + entity.Property(e => e.CreateTime) + .HasComment("创建时间") + .HasColumnType("datetime"); + entity.Property(e => e.Input_tokens).HasComment("输入token"); + entity.Property(e => e.IsDel).HasComment("是否假删除0否1是"); + entity.Property(e => e.Model) + .HasMaxLength(255) + .IsUnicode(false) + .HasComment("人物模型"); + entity.Property(e => e.Output_tokens).HasComment("输出token"); + entity.Property(e => e.Role) + .HasMaxLength(50) + .IsUnicode(false) + .HasComment("user/assistant"); + entity.Property(e => e.TenantId).HasComment("租户id"); + entity.Property(e => e.TimeStamp) + .HasComment("发送时间") + .HasColumnType("datetime"); + entity.Property(e => e.UpdateTime) + .HasComment("更新时间") + .HasColumnType("datetime"); + entity.Property(e => e.UserId).HasComment("聊天内容"); + //添加全局筛选器 + if (this.TenantInfo != null) + { + entity.HasQueryFilter(it => it.TenantId == this.TenantInfo.TenantId); + } + }); + modelBuilder.Entity(entity => { entity.HasKey(e => e.Id).HasName("PK__T_User__3214EC073733108B"); diff --git a/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Character.cs b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Character.cs new file mode 100644 index 0000000..46dceb5 --- /dev/null +++ b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Character.cs @@ -0,0 +1,65 @@ +using System; + +namespace HuanMeng.MiaoYu.Model.DbSqlServer.Db_MiaoYu; + +/// +/// 人物表 +/// +public partial class T_Character: MultiTenantEntity +{ + /// + /// 人物id + /// + public int Id { get; set; } + + /// + /// 人物名字 + /// + public string? Name { get; set; } + + /// + /// 人物简介 + /// + public string? Biography { get; set; } + + + /// + /// 开场白 + /// + public string Prologue { get; set; } = null!; + + /// + /// 风格id + /// + public int? Style { get; set; } + + /// + /// 公开/私密 0公开 1私密 + /// + public bool Visibility { get; set; } + + /// + /// 创建时间 + /// + public DateTime? CreateTime { get; set; } + + /// + /// 更新时间 + /// + public DateTime? UpdateTime { get; set; } + + /// + /// 性别0男1女2其他 + /// + public int Gender { get; set; } + + /// + /// 人物模型 + /// + public string? Model { get; set; } + + /// + /// 人物初始设定 + /// + public string? System { get; set; } +} diff --git a/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Character_Label.cs b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Character_Label.cs new file mode 100644 index 0000000..d2f565c --- /dev/null +++ b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Character_Label.cs @@ -0,0 +1,30 @@ +using System; + +namespace HuanMeng.MiaoYu.Model.DbSqlServer.Db_MiaoYu; + +/// +/// 角色标签表 +/// +public partial class T_Character_Label: MultiTenantEntity +{ + /// + /// 标签id + /// + public int Id { get; set; } + + + /// + /// 标签名称 + /// + public string? LabelName { get; set; } + + /// + /// 创建时间 + /// + public DateTime? CreateTime { get; set; } + + /// + /// 更新时间 + /// + public DateTime? UpdateTime { get; set; } +} 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 new file mode 100644 index 0000000..91e1ed3 --- /dev/null +++ b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Character_Label_Relation.cs @@ -0,0 +1,35 @@ +using System; + +namespace HuanMeng.MiaoYu.Model.DbSqlServer.Db_MiaoYu; + +/// +/// 关联角色和标签 +/// +public partial class T_Character_Label_Relation: MultiTenantEntity +{ + /// + /// 人物和标签的关联id + /// + public int Id { get; set; } + + /// + /// 人物Id + /// + public int? CharacterId_ { get; set; } + + /// + /// 人物标签id + /// + public int? CharacterLabelId { get; set; } + + /// + /// 创建时间 + /// + public DateTime? CreateTime { 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 new file mode 100644 index 0000000..fd0d9dc --- /dev/null +++ b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Character_Type.cs @@ -0,0 +1,30 @@ +using System; + +namespace HuanMeng.MiaoYu.Model.DbSqlServer.Db_MiaoYu; + +/// +/// 发现页类型分类 +/// +public partial class T_Character_Type: MultiTenantEntity +{ + /// + /// 类型id + /// + public int Id { get; set; } + + /// + /// 类型名称 + /// + public string? Name { get; set; } + + + /// + /// 创建时间 + /// + public DateTime CreateTime { get; set; } + + /// + /// 更新时间 + /// + 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 new file mode 100644 index 0000000..17579eb --- /dev/null +++ b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Character_User_Intimacy.cs @@ -0,0 +1,40 @@ +using System; + +namespace HuanMeng.MiaoYu.Model.DbSqlServer.Db_MiaoYu; + +/// +/// 存储用户和角色之间的亲密值 +/// +public partial class T_Character_User_Intimacy: MultiTenantEntity +{ + /// + /// 亲密度id + /// + public int Id { get; set; } + + + /// + /// 人物Id + /// + public int? CharacterId { get; set; } + + /// + /// 用户Id + /// + public int? UserId { get; set; } + + /// + /// 亲密值 + /// + public int? IntimacyValue { get; set; } + + /// + /// 创建时间 + /// + public DateTime? CreateTime { get; set; } + + /// + /// 更新时间 + /// + public DateTime? UpdateTime { get; set; } +} diff --git a/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Chat.cs b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Chat.cs new file mode 100644 index 0000000..f20ee9b --- /dev/null +++ b/src/0-core/HuanMeng.MiaoYu.Model/DbSqlServer/Db_MiaoYu/T_Chat.cs @@ -0,0 +1,75 @@ +using System; + +namespace HuanMeng.MiaoYu.Model.DbSqlServer.Db_MiaoYu; + +/// +/// 聊天记录表 +/// +public partial class T_Chat: MultiTenantEntity +{ + /// + /// 聊天id + /// + public int Id { get; set; } + + + /// + /// 聊天内容 + /// + public int? UserId { get; set; } + + /// + /// 消息内容 + /// + public string Content { get; set; } = null!; + + /// + /// 发送时间 + /// + public DateTime? TimeStamp { get; set; } + + /// + /// 创建时间 + /// + public DateTime? CreateTime { get; set; } + + /// + /// 更新时间 + /// + public DateTime? UpdateTime { get; set; } + + /// + /// 输入token + /// + public int? Input_tokens { get; set; } + + /// + /// 输出token + /// + public int Output_tokens { get; set; } + + /// + /// 人物表Id + /// + public int? CharacterId { get; set; } + + /// + /// user/assistant + /// + public string Role { get; set; } = null!; + + /// + /// 发送日期 + /// + public DateOnly? CreateDay { get; set; } + + /// + /// 是否假删除0否1是 + /// + public bool IsDel { get; set; } + + /// + /// 人物模型 + /// + public string Model { get; set; } = null!; +} diff --git a/src/2-api/HuanMeng.MiaoYu.WebApi/Controllers/ChatController.cs b/src/2-api/HuanMeng.MiaoYu.WebApi/Controllers/ChatController.cs index 03007b1..5d4d257 100644 --- a/src/2-api/HuanMeng.MiaoYu.WebApi/Controllers/ChatController.cs +++ b/src/2-api/HuanMeng.MiaoYu.WebApi/Controllers/ChatController.cs @@ -1,4 +1,5 @@ using HuanMeng.DotNetCore.Base; +using HuanMeng.MiaoYu.Code.Chat; using HuanMeng.MiaoYu.Model.Dto.Home; using HuanMeng.MiaoYu.WebApi.Base; using Microsoft.AspNetCore.Authorization; @@ -21,8 +22,7 @@ namespace HuanMeng.MiaoYu.WebApi.Controllers /// /// [HttpGet] - [AllowAnonymous] - public async Task> GetCharacterInfo(int userId) + public async Task> GetCharacterInfo() { 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}"); @@ -35,11 +35,28 @@ namespace HuanMeng.MiaoYu.WebApi.Controllers /// /// [HttpGet] - [AllowAnonymous] - public async Task> GetChatInfo(int userId) + public async Task> GetChatInfo() { var obj = JsonConvert.DeserializeObject("{\"ChatList\":[{\"Id\":\"1\",\"Role\":\"user\",\"Content\":\"Hello, how are you?\",\"Timestamp\":\"2022-03-01 12:00:00 \",\"MessageType\":0,\"UserIcon\":\"\"},{\"Id\":\"2\",\"Role\":\"assistant\",\"Content\":\"I'm fine, thanks!\",\"Timestamp\":\"2022-03-01 12:05:00 \",\"UserIcon\":\"\"}]}"); return new BaseResponse(ResonseCode.Success, "", obj); } + + /// + /// 删除聊天记录 + /// + /// + /// + /// + [HttpPost] + public async Task> DelChatByIds(List id, int characterId) + { + if(id == null || characterId == 0) + { + throw new ArgumentNullException(); + } + ChatBLL chatBLL = new ChatBLL(ServiceProvider); + var obj =await chatBLL.DelChatByIds(id, characterId); + return new BaseResponse(ResonseCode.Success, "", obj); + } } }