using GDZZ.Core;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System.Linq;
using System.Threading.Tasks;
using GDZZ.Application.Entity;
using System.Collections.Generic;
using K4os.Hash.xxHash;
using GDZZ.Core.Entity;
namespace GDZZ.Application
{
///
/// 聊天服务
///
[ApiDescriptionSettings("Application", Name = "LiveHistoryContacts", Order = 1)]
public class LiveHistoryContactsService : ILiveHistoryContactsService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository _rep;
private readonly SqlSugarRepository liveMessageRep;
private readonly SqlSugarRepository liveUserFriend; //好友表仓储
private readonly SqlSugarRepository _sysUserRep; // 用户表仓储
public LiveHistoryContactsService(SqlSugarRepository rep,
SqlSugarRepository liveUserFriend,
SqlSugarRepository liveMessageRep)
{
_rep = rep;
this.liveUserFriend = liveUserFriend;
this.liveMessageRep = liveMessageRep;
}
///
/// 新增联系人
///
///
[HttpPost("/LiveHistoryContacts/AddLive")]
public async Task AddLive(AddLiveHistoryContactsInput input)
{
var entity = input.Adapt();
await _rep.InsertAsync(entity);
}
///
/// 获取联系人
///
///
///
[HttpGet("/LiveHistoryContacts/list")]
public async Task> List()
{
List historyLists= new List();
//获取好友列表
var friends = await this.liveUserFriend.Where(x => x.CreatedUserId == UserManager.UserId).ToListAsync();
foreach (var item in friends)
{
var friend = await this._sysUserRep.SingleAsync(x => x.Id == item.FriendID);
if (friend == null)
continue;
historyLists.Add(new LiveHistoryLists()
{
Avatar = friend.Avatar,
DisplayName = friend.NickName,
Id = item.FriendID,
Index = friend.Name.Substring(0, 1),
//rm -rf mk dir ls install cd home
}) ;
}
return historyLists;
}
#region 聊天详情
///
/// 获取聊天信息列表
///
///
[HttpGet("/LiveHistoryContacts/GetMessageLists")]
public async Task> GetMessageLists()
{
var res = await this.liveMessageRep.Where(x => x.CreatedUserId == UserManager.UserId || x.OtherUserID == UserManager.UserId).ToListAsync();
return res.Adapt>();
}
///
/// 增加聊天历史任务列表
///
///
///
[HttpPost("/LiveHistoryContacts/addMessage")]
public async Task AddMessage(AddLiveMessageInput input)
{
var entity = input.Adapt();
var history = await this._rep.Where(x => (x.CreatedUserId == input.OtherUserID && x.UserID == UserManager.UserId) || (x.UserID == input.OtherUserID && x.CreatedUserId == UserManager.UserId)).SingleAsync();
await this.liveMessageRep.InsertAsync(entity);
}
#endregion
}
}