public bool SetRead(int sendId)
        {
            _sendAppMessageDal.Update <SendAppMessageEntity>(new SendAppMessageEntity()
            {
                SendId = sendId,
                IsRead = 1
            }, new[] { "IsRead" });

            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// 发送待推送信息
        /// </summary>
        /// <param name="sendAppMessageModels"></param>
        /// <param name="sendAppMessageType"></param>
        public void SendAppMessage(List <SendAppMessageModel> sendAppMessageModels, SendAppMessageTypeEnum sendAppMessageType)
        {
            if (sendAppMessageModels == null || sendAppMessageModels.Count == 0)
            {
                return;
            }
            List <int> cidList = sendAppMessageModels.Select(n => n.Cid).ToList();
            List <CustomerAppClientIdEntity> customerAppClientIdEntities =
                _customerAppClientIdDal.Query <CustomerAppClientIdEntity>(n => cidList.Contains(n.Cid), true).ToList();

            foreach (SendAppMessageModel waitSend in sendAppMessageModels)
            {
                SendAppMessageEntity entity = new SendAppMessageEntity();
                entity.SendId    = waitSend.SendId;
                entity.SendCount = waitSend.SendCount + 1;
                if (!waitSend.SendFirstTime.HasValue)
                {
                    entity.SendFirstTime = DateTime.Now;
                }
                else
                {
                    entity.SendFirstTime = waitSend.SendFirstTime;
                }
                entity.SendLastTime = DateTime.Now;
                CustomerAppClientIdEntity customerAppClientIdEntity = customerAppClientIdEntities.Find(n => n.Cid == waitSend.Cid);
                entity.ClientId = customerAppClientIdEntity?.ClientId;
                if (waitSend.SendCount <= 10 && !string.IsNullOrEmpty(waitSend.SendContent))//发送记录少于10次
                {
                    if (!string.IsNullOrEmpty(entity.ClientId))
                    {
                        #region 推送app消息

                        string message = waitSend.SendContent;
                        if (sendAppMessageType != SendAppMessageTypeEnum.AuditUrgeNotice)
                        {
                            message = string.Format("message={0}&cid={1}&sendType={2}&id={3}&orderType={4}",
                                                    waitSend.SendContent,
                                                    waitSend.Cid, (int)waitSend.SendType, waitSend.OrderId, (int)waitSend.OrderType);
                        }

                        SendAppContentModel content = new SendAppContentModel();
                        content.ClientId   = entity.ClientId;
                        content.ClientType = customerAppClientIdEntity?.ClientType;
                        content.Content    = message;
                        content.Title      = waitSend.SendType.ToDescription();
                        content.Text       = waitSend.SendContent;
                        if (sendAppMessageType == SendAppMessageTypeEnum.AuditUrgeNotice &&
                            !string.IsNullOrEmpty(message) && message.Contains("&"))
                        {
                            content.Text = message.Split('&')[0].Replace("message=", "");
                        }
                        SendAppMessageResultModel resultModel = new SendAppMessageResultModel();
                        try
                        {
                            resultModel        = _sendAppMessageBll.SendAppMessage(content);
                            entity.SendContent = content.Content;
                            entity.SendResult  = resultModel.ResultInfo;
                            if (resultModel.Result.ToLower() == "ok")
                            {
                                entity.SendStatus = 1;
                            }
                            else
                            {
                                entity.SendStatus = -1;
                            }
                        }
                        catch (Exception ex)
                        {
                            entity.SendResult = ex.Message;
                            entity.SendStatus = -2;
                        }

                        #endregion
                    }
                    else
                    {
                        entity.SendStatus = -3;
                        entity.SendResult = "没有找到对应的设备Id";
                    }
                }
                else
                {
                    entity.SendStatus = -4;
                    entity.SendResult = "已经超过10次,不再发送";
                }

                _sendAppMessageDal.Update(entity, new string[] { "SendCount", "SendFirstTime", "SendLastTime", "ClientId", "SendContent", "SendResult", "SendStatus" });
            }
        }