private static void Main(string[] args) { var sys = ActorSystem.Create("sys"); var actor = sys.ActorOf(Props.Create <HelloActor>()); var random = new Random(Guid.NewGuid().GetHashCode()); while (true) { Thread.Sleep(random.Next(5) * 1000); IEnvelope envelope = null; switch (random.Next(1000) % 2) { case 0: envelope = new ImMessage("abc", 1); break; case 1: envelope = new UrMessage("abc", 1); break; } actor.Tell(envelope); } }
/// <summary> /// 获取历史记录 /// </summary> /// <returns></returns> public ActionResult GetHistory() { string appId = Context.GetRequest("appId", string.Empty); if (string.IsNullOrEmpty(appId)) { return(Json(new { isok = false, msg = "appId为空" })); } int fuserId = Context.GetRequestInt("fuserId", 0); if (fuserId <= 0) { return(Json(new { isok = false, msg = "fuserId 为空" })); } int tuserId = Context.GetRequestInt("tuserId", 0); if (tuserId <= 0) { return(Json(new { isok = false, msg = "tuserId为空" })); } int fuserType = Context.GetRequestInt("fuserType", 0); int ver = Context.GetRequestInt("ver", 0);//版本号:0:技师端,1:通用 int id = Context.GetRequestInt("id", 0); List <ImMessage> messageList = ImMessageBLL.SingleModel.GetHistory(id, fuserId, tuserId, fuserType, ver); //设为已读 ImMessage readmodel = messageList?.FirstOrDefault(w => w.isRead == 0); if (readmodel != null) { ImMessageBLL.SingleModel.UpdateIMReadState(tuserId, fuserId); } return(Json(new { isok = true, data = messageList, msg = messageList.Count })); }
public List <QiyeCustomer> GetDataListApi(int userId, int staffId, int pageSize, int pageIndex, ref int count, string name, string appid) { List <QiyeCustomer> list = new List <QiyeCustomer>(); string sql = $@"select {"{0}"} from QiyeCustomer q left join c_userinfo c on q.userid = c.id "; string sqlCount = string.Format(sql, "Count(*)"); //(select count(*) from immessage where tuserid = q.userid and fuserid = { userId } and isread = 0) messagecount,(select msg from immessage where tuserid = q.userid and fuserid = { userId } order by senddate DESC LIMIT 1) msg string sqlList = string.Format(sql, $@"q.*,c.NickName,c.HeadImgUrl,c.TelePhone"); string sqlWhere = $" where q.StaffId={staffId} and q.state>=0 and c.appid='{appid}'"; string sqlPage = $" limit {(pageIndex - 1) * pageSize},{pageSize}"; List <MySqlParameter> parms = new List <MySqlParameter>(); if (!string.IsNullOrEmpty(name)) { sqlWhere += $" and (c.NickName like @name or c.TelePhone like @name or q.Desc like @name)"; parms.Add(new MySqlParameter("@name", $"%{name}%")); } // log4net.LogHelper.WriteInfo(this.GetType(), sqlList + sqlWhere ); count = base.GetCountBySql(sqlCount + sqlWhere, parms.ToArray()); if (count <= 0) { return(list); } // log4net.LogHelper.WriteInfo(this.GetType(), sqlList + sqlWhere + sqlPage); using (MySqlDataReader dr = SqlMySql.ExecuteDataReaderMaster(connName, CommandType.Text, sqlList + sqlWhere + sqlPage, parms.ToArray())) { while (dr.Read()) { QiyeCustomer model = base.GetModel(dr); model.NoReadMessageCount = ImMessageBLL.SingleModel.GetNoReadCount(model.UserId, userId); ImMessage imModel = ImMessageBLL.SingleModel.GetNewMessage(model.UserId, userId, 0, 1); if (imModel != null) { model.LastMsg = imModel.msg; model.MsgType = imModel.msgType; } if (dr["NickName"] != DBNull.Value) { model.Name = Convert.ToString(dr["NickName"]); } if (dr["HeadImgUrl"] != DBNull.Value) { model.HeadImgUrl = dr["HeadImgUrl"].ToString(); } if (dr["TelePhone"] != DBNull.Value) { model.Phone = dr["TelePhone"].ToString(); } list.Add(model); } } return(list); }
/// <summary> /// 拼享惠联系人 /// </summary> /// <param name="tuserId"></param> /// <param name="appid"></param> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <param name="count"></param> /// <returns></returns> public List <ImMessage> GetListByPxh(int tuserId, string appid, int pageSize, int pageIndex, ref int count) { string key = string.Format(redis_ListPxhkey, tuserId); XcxAppAccountRelation xcxrelation = XcxAppAccountRelationBLL.SingleModel.GetModelByAppid(appid); if (xcxrelation == null) { return(new List <ImMessage>()); } List <ImMessage> redisList = RedisUtil.Get <List <ImMessage> >(key); if (pageIndex == 1 || redisList == null || redisList.Count <= 0) { redisList = new List <ImMessage>(); string sql = $"select {"{0}"} from ImContact im left join c_userinfo c on im.fuserid = c.id "; string sqlCount = string.Format(sql, "count(*)"); string sqlList = string.Format(sql, "im.*,c.NickName,c.HeadImgUrl"); string sqlWhere = $" where im.appid = '{appid}' and im.tuserid={tuserId}"; count = base.GetCountBySql(sqlCount + sqlWhere); if (count <= 0) { return(redisList); } using (MySqlDataReader dr = SqlMySql.ExecuteDataReaderMaster(connName, CommandType.Text, sqlList + sqlWhere)) { while (dr.Read()) { ImContact tempmodel = base.GetModel(dr); ImMessage model = new ImMessage(); model.fuserId = tempmodel.fuserId; model.tuserId = tuserId; model.NoReadMessageCount = ImMessageBLL.SingleModel.GetUserNoReadCount(tuserId, tempmodel.fuserId); ImMessage imModel = ImMessageBLL.SingleModel.GetNewMessage(model.fuserId, tuserId, 0, 1); if (imModel != null) { model.LastMsg = imModel.msg; model.msgType = imModel.msgType; model.sendDate = imModel.sendDate; } model.CardImgUrl = dr["HeadImgUrl"].ToString(); model.CardName = dr["NickName"].ToString(); redisList.Add(model); } } string userIds = string.Join(",", redisList.Select(s => s.fuserId)); List <PinStore> storeList = PinStoreBLL.SingleModel.GetListByAidUserId(xcxrelation.Id, userIds); if (storeList != null && storeList.Count > 0) { foreach (ImMessage item in redisList) { PinStore tempStore = storeList.FirstOrDefault(f => f.userId == item.fuserId); if (tempStore != null) { item.StoreName = tempStore.storeName; item.StoreLogImgUrl = tempStore.logo; } } } redisList = redisList.OrderByDescending(o => o.sendDate).ToList(); RedisUtil.Set <List <ImMessage> >(key, redisList); } redisList = redisList.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(); return(redisList); }
/// <summary> /// 企业智推版员工获取联系人 /// </summary> /// <param name="fuserid"></param> /// <param name="appid"></param> /// <returns></returns> public List <ImMessage> GetListByQiye(int tuserId, string appid, int pageSize, int pageIndex, ref int count, string name) { string key = string.Format(redis_ListEmployeekey, tuserId); List <ImMessage> list = new List <ImMessage>(); List <ImMessage> redisList = RedisUtil.Get <List <ImMessage> >(key); if (redisList == null || redisList.Count <= 0 || pageIndex == 1) { redisList = new List <ImMessage>(); string sql = $"select {"{0}"} from ImContact im left join c_userinfo c on im.fuserid = c.id "; string sqlCount = string.Format(sql, "count(*)"); string sqlList = string.Format(sql, "im.*,c.NickName,c.HeadImgUrl"); string sqlWhere = $" where im.appid = '{appid}' and im.tuserid={tuserId}"; string sqlPage = "";//$" limit {(pageIndex - 1) * pageSize},{pageSize}"; List <MySqlParameter> parms = new List <MySqlParameter>(); if (!string.IsNullOrEmpty(name)) { sqlWhere += $" and (c.NickName like @name or c.TelePhone like @name)"; parms.Add(new MySqlParameter("@name", $"%{name}%")); } count = base.GetCountBySql(sqlCount + sqlWhere, parms.ToArray()); if (count <= 0) { return(redisList); } using (MySqlDataReader dr = SqlMySql.ExecuteDataReaderMaster(connName, CommandType.Text, sqlList + sqlWhere + sqlPage, parms.ToArray())) { while (dr.Read()) { ImContact tempmodel = base.GetModel(dr); ImMessage model = new ImMessage(); model.fuserId = tempmodel.fuserId; model.tuserId = tuserId; model.NoReadMessageCount = ImMessageBLL.SingleModel.GetUserNoReadCount(tuserId, tempmodel.fuserId); ImMessage imModel = ImMessageBLL.SingleModel.GetNewMessage(model.fuserId, tuserId, 0, 1); if (imModel != null) { model.LastMsg = imModel.msg; model.msgType = imModel.msgType; model.sendDate = imModel.sendDate; } model.CardImgUrl = dr["HeadImgUrl"].ToString(); model.CardName = dr["NickName"].ToString(); redisList.Add(model); } } string userIds = string.Join(",", redisList.Select(s => s.fuserId).Distinct()); List <QiyeCustomer> customerList = QiyeCustomerBLL.SingleModel.GetListByUserIds(userIds); if (customerList == null || customerList.Count <= 0) { return(redisList); } string empIds = string.Join(",", customerList.Select(s => s.StaffId).Distinct()); List <QiyeEmployee> employeeList = QiyeEmployeeBLL.SingleModel.GetListByIds(empIds); if (employeeList == null || employeeList.Count <= 0) { return(redisList); } foreach (ImMessage item in redisList) { QiyeCustomer customerModel = customerList.FirstOrDefault(f => f.UserId == item.fuserId); if (customerModel == null) { continue; } QiyeEmployee empModel = employeeList.FirstOrDefault(f => f.Id == customerModel.StaffId); if (empModel == null) { continue; } item.Desc = customerModel.Desc; item.EmployeeName = empModel.Name; } RedisUtil.Set <List <ImMessage> >(key, redisList); redisList = redisList.OrderByDescending(o => o.sendDate).ToList(); //list = redisList.Skip((pageIndex-1)*pageSize).Take(pageSize).ToList(); } list = redisList.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(); return(list); }
public List <QiyeCustomer> GetDataList(int aid, string name, int pageSize, int pageIndex, ref int count) { List <QiyeCustomer> list = new List <QiyeCustomer>(); string sql = $"select {"{0}"} from QiyeCustomer c left join QiyeEmployee e on c.staffid=e.id"; string sqlList = string.Format(sql, "c.*,e.name employeename"); string sqlCount = string.Format(sql, "count(*)"); string sqlWhere = $" where c.aid={aid} and c.state>=0"; string sqlPage = $" limit {(pageIndex - 1) * pageSize},{pageSize}"; if (!string.IsNullOrEmpty(name)) { XcxAppAccountRelation xcxrelation = XcxAppAccountRelationBLL.SingleModel.GetModel(aid); if (xcxrelation == null) { return(list); } List <C_UserInfo> userList = C_UserInfoBLL.SingleModel.GetListByName(xcxrelation.AppId, name); if (userList == null || userList.Count <= 0) { return(list); } string userids = string.Join(",", userList.Select(s => s.Id)); sqlWhere += $" and c.userid in ({userids})"; } count = base.GetCountBySql(sqlCount + sqlWhere); using (MySqlDataReader dr = SqlMySql.ExecuteDataReaderMaster(connName, CommandType.Text, sqlList + sqlWhere + sqlPage)) { while (dr.Read()) { QiyeCustomer model = base.GetModel(dr); model.EmployeeName = dr["employeename"].ToString(); list.Add(model); } } if (count > 0) { string userIds = string.Join(",", list.Select(s => s.UserId)); List <C_UserInfo> userList = C_UserInfoBLL.SingleModel.GetListByIds(userIds); //用户咨询发送私信数量 List <ImMessage> imMessageList = ImMessageBLL.SingleModel.GetListByQiyeCustomerUserIds(userIds); //用户买单集合 List <QiyeGoodsOrder> orderList = QiyeGoodsOrderBLL.SingleModel.GetOrderResult(aid, userIds); foreach (QiyeCustomer item in list) { //访问次数和咨询次数 ImMessage imMessageModel = imMessageList?.FirstOrDefault(f => f.fuserId == item.UserId); if (imMessageModel != null) { item.AskCount = imMessageModel.storeId; } C_UserInfo userInfo = userList.FirstOrDefault(f => f.Id == item.UserId); if (userInfo != null) { item.Name = userInfo.NickName; item.Phone = userInfo.TelePhone; item.HeadImgUrl = userInfo.HeadImgUrl; } //总订单数和总订单金额 QiyeGoodsOrder order = orderList?.FirstOrDefault(f => f.UserId == item.UserId); if (order != null) { item.OrderCount = order.QtyCount; item.OrderTotalPrice = order.BuyPrice; } } } return(list); }