Beispiel #1
0
        private void Receive(string identify, ReceiveDataModel model)
        {
            //解析model
            var sendModel = _redis.GetSmsSendModel(model);

            if (sendModel == null)
            {
                return;
            }
            //调用服务发送短信
            if (!sendModel.IsSend)
            {
                return;
            }
            //短信成功后更新oracle表
            if (_send.SendMsg(sendModel) == "000000")
            {
                //更新数据库表
                var configModel = _resp.FirstOrDefault(a => a.Monitor.BMID == sendModel.StationKey);
                if (configModel != null)
                {
                    configModel.LASTTIME  = sendModel.SaveTime;
                    configModel.LASTVALUE = sendModel.Value;
                    _resp.Update(configModel);
                }
                //更新redis缓存
            }
            ;
        }
        public async Task <IActionResult> Contact(SendMessageEntity model)
        {
            if (ModelState.IsValid)
            {
                var response = _mailHelper.SendMail("*****@*****.**",
                                                    $"{model.FirstName + " " + model.LastName} te ha enviado un mensaje desde la pagina web",
                                                    $"<h1> Te han escrito el siguiente mensaje: </h1>" +
                                                    $"<br/>" +
                                                    $"<p>{model.Message}</p>");

                if (response.IsSuccess)
                {
                    ViewBag.Message = "Ha sido enviado el mensaje";
                    _context.Add(model);
                    await _context.SaveChangesAsync();

                    UserEntity user = await _userHelper.GetUserAsync(model.Email);

                    if (user == null)
                    {
                        _dataModel = new ReceiveDataModel(model.Email, model.FirstName, model.LastName);

                        ViewBag.Message = "Si quieres conocer más acerca de la fundación, te invitamos a registrarte";
                        return(RedirectToAction("Register", "Account"));
                    }
                    return(RedirectToAction(nameof(Contact)));
                }
            }
            return(View(model));
        }
Beispiel #3
0
        public SmsSendModel GetSmsSendModel(ReceiveDataModel model)
        {
            var smsModel = new SmsSendModel();

            //短信发送两种逻辑,1、有报警则根据配置的时间间隔进行发送;2、当前与上一次接收的值超过了阈值,进行发送。

            //首先判断此监测点是否报警,若报警,则继续执行下一步
            if (string.IsNullOrEmpty(model.AlertId))
            {
                return(smsModel);
            }


            var stationKey = model.StationKey;

            var cache = _cache.Get <SmsCacheModel>("Default:Kylin:SMS:" + stationKey);

            //根据监测点编号判断是否有缓存
            if (cache == null)
            {
                return(smsModel);
            }

            smsModel.SystemCode = ConfigurationManager.AppSettings["SystemCode"];
            smsModel.IsSend     = cache.IsEnabled != 0;
            var smsInfo = cache.StationName + "," + model.TagName + "," + model.TagValue +
                          model.Units + "," + model.SaveTime;

            smsModel.MsgString  = smsInfo;
            smsModel.MsgTempId  = cache.TemplateId == ""? ConfigurationManager.AppSettings["DefaultTemplateId"] : cache.TemplateId;
            smsModel.Phone      = cache.PhoneString;
            smsModel.StationKey = stationKey;
            smsModel.Value      = decimal.Parse(model.TagValue);
            smsModel.SaveTime   = model.SaveTime;
            if (cache.Interval == 0)
            {
                cache.Interval = int.Parse(ConfigurationManager.AppSettings["DefaultSendInterval"]);
            }

            if (decimal.Parse(model.TagValue) - cache.LastValue >= cache.ChangeDiff)
            {
                //立刻发送
                UpdateCache(stationKey, cache, model.TagValue, model.SaveTime);
                return(smsModel);
            }
            else if (cache.LastTime.AddMinutes((int)cache.Interval) <= DateTime.Now)
            {
                //根据时间间隔发送
                UpdateCache(stationKey, cache, model.TagValue, model.SaveTime);
                return(smsModel);
            }
            else
            {
                return(null);
            }
        }
Beispiel #4
0
        private void Receive(string identify, ReceiveDataModel model)
        {
            try
            {
                //进行数据解析
                var list = _resolution.GetLedModel(model);
                if (list.Count > 0)
                {
                    foreach (var data in list)
                    {
                        //正常信息
                        if (data.IsNormal)
                        {
                            //如果属于正常发送,则需要存储第一次发送的时间,若超过指定时间段则重新随机发送,每一个控制卡存储一个时间点
                            var lasttime = _cache.Get <object>(data.CardCode);

                            if (lasttime != null)
                            {
                                //超过半小时进行发送
                                if ((DateTime.Now - (DateTime)lasttime).TotalMinutes > 30)
                                {
                                    data.Content = GetContent(data.Level);
                                }
                                //data.Content = GetContent(data.Level);
                                // todo 执行发送
                            }
                            else
                            {
                                //保存发送时间
                                _cache.Add(data.CardCode, DateTime.Now);

                                data.Content = GetContent(data.Level);

                                // todo 执行发送
                            }
                        }
                        else
                        {
                            //有降雨的情况
                            var content = GetContent(data.Level);
                            data.Content = @"当前积水:" + model.TagValue + model.Units + "," + content;

                            // todo 执行发送

                            //todo  预留的功能,需要发送短信息,待讨论
                            if (data.IsSendMsg)
                            {
                                //给运维人员发送短信,通知当前led的内容

                                var msg = @"系统服务自动发送了Led信息【" + data.Content + "】,请确认";

                                //_resolution.SendMsg()
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _log.Error(e.Message);
            }
        }