using Learun.Application.IM;
using Learun.Util;
using System.Web.Mvc;
namespace Learun.Application.Web.Areas.LR_IM.Controllers
{
///
/// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
/// Copyright (c) 2013-2018 北京泉江科技有限公司
/// 创 建:超级管理员
/// 日 期:2018-05-24 10:00
/// 描 述:即时通讯
///
public class IMMsgController : MvcControllerBase
{
private IMMsgIBLL iMMsgIBLL = new IMMsgBLL();
private IMSysUserIBLL iMSysUserIBLL = new IMSysUserBLL();
private IMContactsIBLL iMContactsIBLL = new IMContactsBLL();
#region 视图功能
///
/// 聊天记录
///
///
[HttpGet]
public ActionResult Index()
{
return View();
}
#endregion
#region 获取数据
///
/// 获取列表数据(消息的最近10条数据)
///
/// 对方用户ID
///
[HttpGet]
[AjaxOnly]
public ActionResult GetMsgList(string userId)
{
UserInfo userInfo = LoginUserInfo.Get();
var data = iMMsgIBLL.GetList(userInfo.userId, userId);
return JsonResult(data);
}
///
/// 获取列表分页数据(消息列表)
///
/// 分页参数
/// 对方用户ID
/// 查询关键字
///
[HttpGet]
[AjaxOnly]
public ActionResult GetMsgPageList(string pagination, string userId, string keyWord)
{
Pagination paginationobj = pagination.ToObject();
UserInfo userInfo = LoginUserInfo.Get();
var data = iMMsgIBLL.GetPageList(paginationobj, userInfo.userId, userId, keyWord);
var jsonData = new
{
rows = data,
total = paginationobj.total,
page = paginationobj.page,
records = paginationobj.records
};
return JsonResult(jsonData);
}
///
/// 获取最近联系人列表
///
///
[HttpGet]
[AjaxOnly]
public ActionResult GetContactsList()
{
UserInfo userInfo = LoginUserInfo.Get();
var sysUserList = iMSysUserIBLL.GetList("");
var data = iMContactsIBLL.GetList(userInfo.userId);
var jsonData = new
{
data,
sysUserList
};
return Success(jsonData);
}
#endregion
#region 提交数据
///
/// 保存实体数据(新增、修改)
/// 接收方用户id
/// 消息内容
/// 是否是系统消息:0不是,1是
///
///
[HttpPost]
[AjaxOnly]
//public ActionResult SendMsg(string userId, string content, int isSystem)
public ActionResult SendMsg(string userId, string content)
{
UserInfo userInfo = LoginUserInfo.Get();
IMMsgEntity entity = new IMMsgEntity();
entity.F_SendUserId = userInfo.userId;
entity.F_RecvUserId = userId;
entity.F_Content = content;
//entity.F_IsSystem = isSystem;
iMMsgIBLL.SaveEntity(entity);
return Success("保存成功!");
}
///
/// 添加一条最近的联系人
///
/// 对方用户Id
///
[HttpPost]
[AjaxOnly]
public ActionResult AddContact(string otherUserId)
{
IMContactsEntity entity = new IMContactsEntity();
UserInfo userInfo = LoginUserInfo.Get();
entity.F_MyUserId = userInfo.userId;
entity.F_OtherUserId = otherUserId;
iMContactsIBLL.SaveEntity(entity);
return Success("保存成功!");
}
///
/// 移除一个最近的联系人
///
///
[HttpPost]
[AjaxOnly]
public ActionResult RemoveContact(string otherUserId)
{
UserInfo userInfo = LoginUserInfo.Get();
iMContactsIBLL.DeleteEntity(userInfo.userId, otherUserId);
return Success("移除成功!");
}
///
/// 更新联系人消息读取状态
///
///
///
[HttpPost]
[AjaxOnly]
public ActionResult UpdateContactState(string otherUserId)
{
UserInfo userInfo = LoginUserInfo.Get();
iMContactsIBLL.UpdateState(userInfo.userId, otherUserId);
return Success("保存成功!");
}
#endregion
}
}