using learun.iapplication; using learun.util; using Microsoft.AspNetCore.Mvc; using System.Threading.Tasks; // For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 namespace EC.Web.Areas.LR_IM.Controllers { /// /// 版 本 EasyCode EC管理后台 /// Copyright (c) 2019-present EC管理有限公司 /// 创建人:tobin /// 日 期:2019.11.07 /// 描 述:即时通讯 /// [Area("LR_IM")] public class IMMsgController : MvcControllerBase { private readonly IMMsgIBLL _iMMsgIBLL; private readonly IMSysUserIBLL _iMSysUserIBLL; private readonly IMContactsIBLL _iMContactsIBLL; public IMMsgController(IMMsgIBLL iMMsgIBL, IMSysUserIBLL iMSysUserIBLL, IMContactsIBLL iMContactsIBLL) { _iMMsgIBLL = iMMsgIBL; _iMSysUserIBLL = iMSysUserIBLL; _iMContactsIBLL = iMContactsIBLL; } #region 视图功能 /// /// 聊天记录 /// /// [HttpGet] public IActionResult Index() { return View(); } #endregion 视图功能 #region 获取数据 /// /// 获取列表数据(消息的最近10条数据) /// /// 对方用户ID /// [HttpGet] [AjaxOnly] public async Task GetMsgList(string userId) { var userInfo = await this.CurrentUser(); var data = await _iMMsgIBLL.GetList(userInfo.F_UserId, userId); return Success(data); } /// /// 获取列表分页数据(消息列表) /// /// 分页参数 /// 对方用户ID /// 查询关键字 /// [HttpGet] [AjaxOnly] public async Task GetMsgPageList(string pagination, string userId, string keyWord) { Pagination paginationobj = pagination.ToObject(); var userInfo = await this.CurrentUser(); var data = await _iMMsgIBLL.GetPageList(paginationobj, userInfo.F_UserId, userId, keyWord); var jsonData = new { rows = data, paginationobj.total, paginationobj.page, paginationobj.records }; return Success(jsonData); } /// /// 获取最近联系人列表 /// /// [HttpGet] [AjaxOnly] public async Task GetContactsList() { var sysUserList = await _iMSysUserIBLL.GetList(""); var data = await _iMContactsIBLL.GetList(GetUserId()); var jsonData = new { data, sysUserList }; return Success(jsonData); } #endregion 获取数据 #region 提交数据 /// /// 保存实体数据(新增、修改) /// /// 接收方用户id /// 消息内容 /// [HttpPost] [AjaxOnly] public async Task SendMsg(string userId, string content) { var userInfo = await this.CurrentUser(); IMMsgEntity entity = new IMMsgEntity { F_SendUserId = userInfo.F_UserId, F_RecvUserId = userId, F_Content = content }; await _iMMsgIBLL.SaveEntity(entity); return SuccessInfo("保存成功!"); } /// /// 添加一条最近的联系人 /// /// 对方用户Id /// [HttpPost] [AjaxOnly] public async Task AddContact(string otherUserId) { var userInfo = await this.CurrentUser(); IMContactsEntity entity = new IMContactsEntity { F_MyUserId = userInfo.F_UserId, F_OtherUserId = otherUserId }; await _iMContactsIBLL.SaveEntity(entity); return SuccessInfo("保存成功!"); } /// /// 移除一个最近的联系人 /// /// [HttpPost] [AjaxOnly] public async Task RemoveContact(string otherUserId) { var userInfo = await this.CurrentUser(); await _iMContactsIBLL.DeleteEntity(userInfo.F_UserId, otherUserId); return SuccessInfo("移除成功!"); } /// /// 更新联系人消息读取状态 /// /// /// [HttpPost] [AjaxOnly] public async Task UpdateContactState(string otherUserId) { var userInfo = await this.CurrentUser(); await _iMContactsIBLL.UpdateState(userInfo.F_UserId, otherUserId); return SuccessInfo("保存成功!"); } #endregion 提交数据 } }