|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 聊天服务
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ApiDescriptionSettings("Application", Name = "LiveHistoryContacts", Order = 1)]
|
|
|
|
|
public class LiveHistoryContactsService : ILiveHistoryContactsService, IDynamicApiController, ITransient
|
|
|
|
|
{
|
|
|
|
|
private readonly SqlSugarRepository<LiveHistoryContacts> _rep;
|
|
|
|
|
private readonly SqlSugarRepository<LiveMessage> liveMessageRep;
|
|
|
|
|
private readonly SqlSugarRepository<LiveUserFriend> liveUserFriend; //好友表仓储
|
|
|
|
|
private readonly SqlSugarRepository<SysUser> _sysUserRep; // 用户表仓储
|
|
|
|
|
public LiveHistoryContactsService(SqlSugarRepository<LiveHistoryContacts> rep,
|
|
|
|
|
SqlSugarRepository<LiveUserFriend> liveUserFriend,
|
|
|
|
|
SqlSugarRepository<LiveMessage> liveMessageRep)
|
|
|
|
|
{
|
|
|
|
|
_rep = rep;
|
|
|
|
|
this.liveUserFriend = liveUserFriend;
|
|
|
|
|
this.liveMessageRep = liveMessageRep;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 新增联系人
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/LiveHistoryContacts/AddLive")]
|
|
|
|
|
public async Task AddLive(AddLiveHistoryContactsInput input)
|
|
|
|
|
{
|
|
|
|
|
var entity = input.Adapt<LiveHistoryContacts>();
|
|
|
|
|
await _rep.InsertAsync(entity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取联系人
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("/LiveHistoryContacts/list")]
|
|
|
|
|
public async Task<List<LiveHistoryLists>> List()
|
|
|
|
|
{
|
|
|
|
|
List<LiveHistoryLists> historyLists= new List<LiveHistoryLists>();
|
|
|
|
|
//获取好友列表
|
|
|
|
|
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 聊天详情
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取聊天信息列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("/LiveHistoryContacts/GetMessageLists")]
|
|
|
|
|
public async Task<List<LiveMessageList>> GetMessageLists()
|
|
|
|
|
{
|
|
|
|
|
var res = await this.liveMessageRep.Where(x => x.CreatedUserId == UserManager.UserId || x.OtherUserID == UserManager.UserId).ToListAsync();
|
|
|
|
|
return res.Adapt<List<LiveMessageList>>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 增加聊天历史任务列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/LiveHistoryContacts/addMessage")]
|
|
|
|
|
public async Task AddMessage(AddLiveMessageInput input)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var entity = input.Adapt<LiveMessage>();
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|