删除聊天记录

This commit is contained in:
bibabo 2024-07-15 14:31:01 +08:00
parent bdcf89bc35
commit b548c6e73f
4 changed files with 133 additions and 22 deletions

View File

@ -32,19 +32,17 @@ namespace HuanMeng.MiaoYu.Code.Chat
/// <returns></returns>
public async Task<bool> DelChatByIds(List<int> id, int characterId)
{
//var charactersList = MiaoYuCache.CharactersList;
//List<T_Character> list = _characterCache.GetCharacterFromCache(characterId);
//var chatsToDelete = await Dao.daoDbMiaoYu.context.T_Chat.Where(t => id.Contains(t.Id)).ToListAsync();
//if (chatsToDelete.Count <= 0)
//{
// throw new Exception("");
//}
//var chatList = chatsToDelete.Where(t => t.UserId == _UserId && t.CharacterId == characterId && t.Type == 0).ToList();
//if (chatList.Count > 0)
//{
// chatList.ForEach(t => t.Type = 2);
//}
//Dao.daoDbMiaoYu.context.SaveChanges();
var chatsToDelete = await Dao.daoDbMiaoYu.context.T_Chat.Where(t => id.Contains(t.Id)).ToListAsync();
if (chatsToDelete.Count <= 0)
{
throw new Exception("删除失败");
}
var chatList = chatsToDelete.Where(t => t.UserId == _UserId && t.CharacterId == characterId && (t.Type == (int)ChatType. || t.Type == (int)ChatType.)).ToList();
if (chatList.Count > 0)
{
chatList.ForEach(t => t.Type = 2);
}
Dao.daoDbMiaoYu.context.SaveChanges();
return true;
}
@ -55,12 +53,12 @@ namespace HuanMeng.MiaoYu.Code.Chat
/// <returns></returns>
public async Task<bool> DelChat(int characterId)
{
//var tempList = await Dao.daoDbMiaoYu.context.T_Chat.Where(t => t.UserId == _UserId && t.CharacterId == characterId && t.IsDel == false).ToListAsync();
//if (tempList.Count > 0)
//{
// tempList.ForEach(t => t.IsDel = true);
//}
//Dao.daoDbMiaoYu.context.SaveChanges();
var tempList = await Dao.daoDbMiaoYu.context.T_User_Char.Where(t => t.UserId == _UserId && t.CharacterId == characterId && t.IsDelete == false).FirstOrDefaultAsync();
if (tempList != null)
{
tempList.IsDelete = true;
}
Dao.daoDbMiaoYu.context.SaveChanges();
return true;
}
}

View File

@ -76,8 +76,8 @@ namespace HuanMeng.MiaoYu.Model.Dto.Home
/// </summary>
public class LabelDto
{
public int Id { get; set; }
public string Name { get; set; }
public int LabelId { get; set; }
public string LabelName { get; set; }
}
/// <summary>
@ -130,4 +130,44 @@ namespace HuanMeng.MiaoYu.Model.Dto.Home
/// </summary>
public int CharacterId { get; set; }
}
/// <summary>
/// 聊天表信息状态
/// </summary>
public enum ChatType
{
/// <summary>
/// 正常
/// </summary>
= 0,
/// <summary>
/// 重新生成
/// </summary>
= 1,
/// <summary>
/// 删除
/// </summary>
= 2
}
/// <summary>
/// 角色分类
/// </summary>
public enum Role
{
/// <summary>
/// 用户
/// </summary>
user,
/// <summary>
/// AI
/// </summary>
assistant,
/// <summary>
/// 提示
/// </summary>
tips
}
}

View File

@ -0,0 +1,73 @@
using HuanMeng.MiaoYu.Model.Dto.Home;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HuanMeng.MiaoYu.Model.Dto.Find
{
public class RecommendDto<T> where T : class
{
/// <summary>
/// 热门推荐、热门小说角色、Banner
/// </summary>
public string Title { get; set; }
/// <summary>
/// tuijian xiaoshuo Banner
/// </summary>
public string Type { get; set; }
/// <summary>
///
/// </summary>
public List<T> Data { get; set; }
}
/// <summary>
///
/// </summary>
public class DataListBaseDto
{
/// <summary>
/// 图片地址
/// </summary>
public string ImageUrl { get; set; }
/// <summary>
/// 跳角色、跳页面、跳商城
/// </summary>
public string ActionType { get; set; }
/// <summary>
/// 行为id
/// </summary>
public int ActionId { get; set; }
}
/// <summary>
///
/// </summary>
public class DataListDto : DataListBaseDto
{
/// <summary>
/// 角色名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 人物简介
/// </summary>
public string Biography { get; set; }
/// <summary>
/// 人物性别
/// </summary>
public int Gender { get; set; }
/// <summary>
/// 人物标签
/// </summary>
public List<LabelDto> Label { get; set; }
}
}

View File

@ -37,7 +37,7 @@ namespace HuanMeng.MiaoYu.WebApi.Controllers
public async Task<BaseResponse<List<CharacterInfoDto>>> GetCharacterInfo()
{
var obj = JsonConvert.DeserializeObject<List<CharacterInfoDto>>("[{\"Icon\":\"\",\"Intimacy\":10,\"CharacterId\":2,\"CharacterName\":\"许荷姻\",\"Gender\":1,\"LookCount\":2,\"BgUrl\":\"\",\"Biography\":\"你那商业联姻得来的妻子,原本的天才女孩,聪明伶俐,生的漂亮、端庄,不知贵圈多少人梦寐以求的存在。\",\"Prologue\":\"坐在轮椅上,眼神平静的看着你,语气也同样平静)你回来了。饭菜在桌上,我刚刚热了。(说到这,又垂下眸子道)我还做了碗醒酒汤,记得喝\",\"Label\":[{\"Id\":1,\"Name\":\"美女\"},{\"Id\":2,\"Name\":\"二次元\"}],\"RemainingChatCount\":1}]");
var obj = JsonConvert.DeserializeObject<List<CharacterInfoDto>>("[{\"Icon\":\"\",\"Intimacy\":10,\"CharacterId\":2,\"CharacterName\":\"许荷姻\",\"Gender\":1,\"LookCount\":2,\"BgUrl\":\"\",\"Biography\":\"你那商业联姻得来的妻子,原本的天才女孩,聪明伶俐,生的漂亮、端庄,不知贵圈多少人梦寐以求的存在。\",\"Prologue\":\"坐在轮椅上,眼神平静的看着你,语气也同样平静)你回来了。饭菜在桌上,我刚刚热了。(说到这,又垂下眸子道)我还做了碗醒酒汤,记得喝\",\"Label\":[{\"LabelId\":1,\"LabelName\":\"美女\"},{\"LabelId\":2,\"LabelName\":\"二次元\"}],\"RemainingChatCount\":1}]");
return new BaseResponse<List<CharacterInfoDto>>(ResonseCode.Success, "", obj);
}