111 lines
4.4 KiB
C#
111 lines
4.4 KiB
C#
using HuanMeng.DotNetCore.Base;
|
|
using HuanMeng.MiaoYu.Code.Character;
|
|
using HuanMeng.MiaoYu.Code.Chat;
|
|
using HuanMeng.MiaoYu.Model.Dto.Character;
|
|
using HuanMeng.MiaoYu.Model.Dto.Chat;
|
|
using HuanMeng.MiaoYu.WebApi.Base;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
namespace HuanMeng.MiaoYu.WebApi.Controllers
|
|
{
|
|
|
|
/// <summary>
|
|
/// 首页聊天
|
|
/// </summary>
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class ChatController : MiaoYuControllerBase
|
|
{
|
|
private ChatBLL _chatBLL;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="_serviceProvider"></param>
|
|
public ChatController(IServiceProvider _serviceProvider) : base(_serviceProvider)
|
|
{
|
|
_chatBLL = new ChatBLL(_serviceProvider);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取角色Id
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[AllowAnonymous]
|
|
public BaseResponse<List<int>> GetCharacterIdList()
|
|
{
|
|
CharacterBLL characterBLL = new CharacterBLL(ServiceProvider);
|
|
var obj = characterBLL.GetCharacters();
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取角色人物信息
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[AllowAnonymous]
|
|
public async Task<BaseResponse<CharacterInfoDto>> GetCharacterInfo([FromQuery] RequestCharacterInfo requestCharacterInfo)
|
|
{
|
|
CharacterBLL characterBLL = new CharacterBLL(ServiceProvider);
|
|
var obj = await characterBLL.GetCharacterInfo(requestCharacterInfo);
|
|
return obj;
|
|
|
|
//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}]");
|
|
//return new BaseResponse<List<CharacterInfoDto>>(ResonseCode.Success, "", obj);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取聊天列表信息
|
|
/// </summary>
|
|
/// <param name="characterId"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[AllowAnonymous]
|
|
public async Task<BaseResponse<ChatListDto>> GetChatInfo(int characterId)
|
|
{
|
|
var obj = JsonConvert.DeserializeObject<ChatListDto>("{\"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<ChatListDto>(ResonseCode.Success, "", obj);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除聊天记录
|
|
/// </summary>
|
|
/// <param name="delChat"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="ArgumentNullException"></exception>
|
|
[HttpPost]
|
|
[AllowAnonymous]
|
|
public async Task<BaseResponse<bool>> DelChatByIds([FromBody] DelChat delChat)
|
|
{
|
|
if (delChat.Id == null || delChat.CharacterId == 0)
|
|
{
|
|
throw new ArgumentNullException();
|
|
}
|
|
//ChatBLL chatBLL = new ChatBLL(ServiceProvider);
|
|
var obj = await _chatBLL.DelChatByIds(delChat.Id, delChat.CharacterId);
|
|
return new BaseResponse<bool>(ResonseCode.Success, "", obj);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 清空聊天记录
|
|
/// </summary>
|
|
/// <param name="characterId">人物id</param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[AllowAnonymous]
|
|
public async Task<BaseResponse<bool>> DelChat([FromBody] DelChatList delChatList)
|
|
{
|
|
//ChatBLL chatBLL = new ChatBLL(ServiceProvider);
|
|
var obj = await _chatBLL.DelChat(delChatList.CharacterId);
|
|
return new BaseResponse<bool>(ResonseCode.Success, "", obj);
|
|
}
|
|
}
|
|
}
|