public int AddAppClientId(AddAppClientIdModel query) { //判断是否存在该设备信息 CustomerAppClientIdEntity entity = _customerAppClientIdDal.Query <CustomerAppClientIdEntity>( n => n.Cid == query.Cid, true).FirstOrDefault(); if (entity != null) { if (entity.ClientId != query.ClientId) { //更新 entity.ClientId = query.ClientId; entity.ClientType = query.ClientType; entity.CreateTime = DateTime.Now; _customerAppClientIdDal.Update(entity, new string[] { "ClientId", "ClientType", "CreateTime" }); } } else { CustomerAppClientIdEntity customerAppClientIdEntity = Mapper.Map <AddAppClientIdModel, CustomerAppClientIdEntity>(query); //新增 customerAppClientIdEntity = _customerAppClientIdDal.Insert(customerAppClientIdEntity); } return(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" }); } }