150 lines
4.9 KiB
C#
150 lines
4.9 KiB
C#
using HuanMeng.DotNetCore.Base;
|
|
using HuanMeng.MiaoYu.Code.Cache;
|
|
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.Model.Dto.Shop;
|
|
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<CharacterIdModel>> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 聊天-获取聊天记录
|
|
/// </summary>
|
|
/// <param name="characterId"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[AllowAnonymous]
|
|
public async Task<BaseResponse<List<ChatMessageDto>>> GetChatInfo(int characterId)
|
|
{
|
|
|
|
ChatBLL chatBLL = new ChatBLL(ServiceProvider);
|
|
var list = await chatBLL.GetChatMessage(characterId);
|
|
|
|
return list;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 聊天-发送消息接口
|
|
/// </summary>
|
|
/// <param name="requestMessage"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<BaseResponse<ChatMessageDataDto>> SendMessage([FromBody] RequestMessage requestMessage)
|
|
{
|
|
ChatBLL chatBLL = new ChatBLL(ServiceProvider);
|
|
var obj = await chatBLL.Message(requestMessage.CharacterId, requestMessage.Message);
|
|
return 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);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 聊天-获取消息页面的聊天记录列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[AllowAnonymous]
|
|
public async Task<BaseResponse<List<ChatHistoryInfo>>> GetChatHistoryList()
|
|
{
|
|
var obj = await _chatBLL.GetChatHistoryList();
|
|
return obj;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取记忆卡列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[AllowAnonymous]
|
|
public async Task<BaseResponse<List<PropInfoDto>>> GetMemoryCardInfo()
|
|
{
|
|
var obj = JsonConvert.DeserializeObject<List<PropInfoDto>>("[{\"PropId\":\"1\",\"PropName\":\"记忆卡1\",\"ImgUrl\":\"\"},{\"PropId\":\"2\",\"PropName\":\"记忆卡2\",\"ImgUrl\":\"\"}]");
|
|
return new BaseResponse<List<PropInfoDto>>(ResonseCode.Success, "", obj);
|
|
}
|
|
}
|
|
}
|