Exemplo n.º 1
0
 public JsonResult deleteEquipment([FromBody] deleteEquipment value)
 {
     try
     {
         var id    = value.id;
         var token = value.token;
         var cache = CacheUntity.GetCache <UserCacheModel>(token);
         var equip = _equipment.GetByID(id);
         if (string.IsNullOrEmpty(equip.birdhouse_id))
         {
             equip.member_id    = "";
             equip.bind_status  = "";
             equip.birdhouse_id = "";
             _equipment.Update(equip);
             var model = _cache.FillCacheWithToken(token, cache.member);
             CacheUntity.SetCache(token, model.Result);
             return(Json(new { code = 1, status = "success", msg = "解绑成功" }));
         }
         else
         {
             return(Json(new { code = -1, status = "fail", msg = "此设备已绑定禽舍无法解绑" }));
         }
     }
     catch (Exception e)
     {
         LogHelper.Error(JsonConvert.SerializeObject(e));
         return(Json(new nologin()));
     }
 }
Exemplo n.º 2
0
 public JsonResult deleteBir()
 {
     try
     {
         var token = Request.Query["token"][0];
         var id    = Request.Query["id"][0];
         //var token = value.token ;
         //var id = value.id;
         var cache = CacheUntity.GetCache <UserCacheModel>(token);
         _birdhouse.Delete(id.ToInt());
         var equip = _equipment.GetBybirdhouse_id(id.ToInt());
         equip.member_id    = null;
         equip.birdhouse_id = null;
         equip.bind_status  = "0";
         _equipment.Update(equip);
         var model = _cache.FillCacheWithToken(token, cache.member);
         CacheUntity.SetCache(token, model.Result);
         return(Json(new { code = 1, status = "success", msg = "添加成功" }));
     }
     catch (Exception e)
     {
         LogHelper.Error(JsonConvert.SerializeObject(e));
         return(Json(new nologin()));
     }
 }
Exemplo n.º 3
0
 public JsonResult addEqu([FromBody] addEqu value)
 {
     try
     {
         var serial = value.serial;
         var token  = value.token;
         //var cached = _cache.GetCacheByToken(token);
         //var member_id = cached.Result.member.id.ToInt();
         var cache = CacheUntity.GetCache <UserCacheModel>(token);
         var equip = _equipment.GetByserial(serial);
         if (equip.bind_status == "1")
         {
             return(Json(new { code = 1, status = "success", msg = "此设备已被添加" }));
         }
         else
         {
             //var cached = _cache.GetCacheByToken(token);
             equip.member_id   = cache.member.id;
             equip.bind_status = "1";
             equip.status      = "1";
             _equipment.Update(equip);
             var model = _cache.FillCacheWithToken(token, cache.member);
             CacheUntity.SetCache(token, model.Result);
             return(Json(new { code = 1, status = "success", msg = "添加成功" }));
         }
     }
     catch (Exception e)
     {
         LogHelper.Error(JsonConvert.SerializeObject(e));
         return(Json(new nologin()));
     }
 }
Exemplo n.º 4
0
 public JsonResult editNickName([FromBody] editNickName model)
 {
     try
     {
         var name  = model.nick_name;
         var token = model.token;
         if (string.IsNullOrEmpty(token))
         {
             return(Json(new notoken {
             }));
         }
         var id    = 0;
         var cache = CacheUntity.GetCache <UserCacheModel>(token);
         id = cache.member.id.ToInt();
         var user = _adminRepository.GetByID(id);
         user.nick_name         = name;
         cache.member.nick_name = name;
         user.update_time       = Util.ToUnixStamp(DateTime.Now).ToString();
         _adminRepository.Update(user);
         var model1 = _cache.FillCacheWithToken(token, cache.member);
         CacheUntity.SetCache(token, model1.Result);
         return(Json(new memberedit()));
     }
     catch (Exception e)
     {
         LogHelper.Error(JsonConvert.SerializeObject(e));
         return(Json(new nologin()));
     }
 }
Exemplo n.º 5
0
        public JsonResult dataCurve()
        {
            try
            {
                var       token = Request.Query["token"][0];
                var       id    = Request.Query["id"][0];
                var       cache = CacheUntity.GetCache <UserCacheModel>(token);
                dataCurve cuve  = new dataCurve();
                cuve.status = "success";
                cuve.code   = 1;
                cuve.data   = new dataCurveData();
                var temph = _equipment.GethumidityData(id);
                var tempt = _equipment.GettemperatureData(id);
                cuve.data.humidity    = new List <float>();
                cuve.data.temperature = new List <float>();
                cuve.data.humidity    = temph;
                cuve.data.temperature = tempt;

                return(Json(cuve));
            }
            catch (Exception e)
            {
                LogHelper.Error(JsonConvert.SerializeObject(e));
                return(Json(new nologin()));
            }
        }
Exemplo n.º 6
0
        public JsonResult getMemberInfo(string token)
        {
            try
            {
                if (string.IsNullOrEmpty(token))
                {
                    return(Json(new notoken {
                    }));
                }
                memberModel model = new memberModel();
                int         id    = 0;
                //var cached = _cache.GetCacheByToken(token);
                var cache = CacheUntity.GetCache <UserCacheModel>(token);
                id = cache.member.id.ToInt();
                var user = _adminRepository.GetByID(id);
                model.data = new memberData
                {
                    id          = user.id.ToInt(),
                    avatar      = user.avatar,
                    create_time = user.create_time,
                    mobile      = user.mobile,
                    nick_name   = user.nick_name,
                    username    = user.username
                };

                return(Json(model));
            }
            catch (Exception e)
            {
                LogHelper.Error(JsonConvert.SerializeObject(e));
                return(Json(new nologin()));
            }
            //finally { }
        }
Exemplo n.º 7
0
 public JsonResult editBir([FromBody] editBirModel value)
 {
     try
     {
         var token = value.token;
         var cache = CacheUntity.GetCache <UserCacheModel>(token);
         //var birdModelStr = value.model;
         //var birdModel = value.model;
         //JsonConvert.DeserializeObject<Birdhouse>(birdModelStr);
         Birdhouse birdhouse = _birdhouse.GetByID(value.id);
         birdhouse.update_time = Util.ToUnixStamp(DateTime.Now).ToString();
         //{"token":"08ea69102b204b09bd66cdbcf661dfef","min_temperature":"12","max_temperature":"23","min_humidity":"11"
         //,"max_humidity":"22","warning_ammonia_concentration":0,"warning_negative_pressure":0,"id":238}
         birdhouse.min_humidity    = value.min_humidity.ToString("F1");
         birdhouse.min_temperature = value.min_temperature.ToString("F1");
         birdhouse.max_humidity    = value.max_humidity.ToString("F1");
         birdhouse.max_temperature = value.max_temperature.ToString("F1");
         birdhouse.warning_ammonia_concentration = value.warning_ammonia_concentration.ToString();
         birdhouse.warning_negative_pressure     = value.warning_negative_pressure.ToString();
         _birdhouse.Update(birdhouse);
         var model1 = _cache.FillCacheWithToken(token, cache.member);
         CacheUntity.SetCache(token, model1.Result);
         var model = new CacheModel();
         model.serial = birdhouse.equipment_id;
         var equip = _equipment.GetCacheModelByserial(model.serial);
         model.bind_status     = equip.bind_status;
         model.birdhouse_name  = equip.birdhouse_name;
         model.phone           = 5;
         model.sms             = 5;
         model.smsEnableFlag   = true;
         model.call_num        = 0;
         model.max_humidity    = equip.max_humidity;
         model.min_humidity    = equip.min_humidity;
         model.max_temperature = equip.max_temperature;
         model.min_temperature = equip.min_temperature;
         model.warning_ammonia_concentration = equip.warning_ammonia_concentration;
         model.warning_negative_pressure     = equip.warning_negative_pressure;
         model.name            = equip.name;
         model.status          = equip.status;
         model.username        = equip.username;
         model.warning_mobile  = equip.warning_mobile;
         model.currentTemp     = "0";
         model.currentHumidity = "0";
         model.currentPower    = "0";
         model.setDate         = DateTime.Now.Date;
         CacheUntity.SetCache(birdhouse.equipment_id, model);
         return(Json(new { code = 1, status = "success", msg = "添加成功" }));
     }
     catch (Exception e)
     {
         LogHelper.Error(JsonConvert.SerializeObject(e));
         return(Json(new nologin()));
     }
 }
Exemplo n.º 8
0
        public Task <UserCacheModel> FillCacheWithToken(string token, Member member)
        {
            UserCacheModel model = new UserCacheModel();

            model.token      = token;
            model.member     = member;
            model.id         = member.id;
            model.birdhouses = new List <Birdhouse>();
            #region birdhouses
            model.birdhouses.AddRange(_birdhouse.GetAllByMember(member.id.ToInt()));
            #endregion
            #region CacheModel
            model.cacheModels = new List <CacheModel>();
            foreach (var item in model.birdhouses)
            {
                if (CacheUntity.Exists(item.equipment_id))
                {
                    var devicecache = CacheUntity.GetCache <CacheModel>(item.equipment_id);
                    model.cacheModels.Add(devicecache);
                }
                else
                {
                    var cacheModel = new CacheModel();
                    cacheModel.serial = item.equipment_id;
                    var equip = _equipmentRepository.GetCacheModelByserial(cacheModel.serial);
                    cacheModel.bind_status     = equip.bind_status;
                    cacheModel.birdhouse_name  = equip.birdhouse_name;
                    cacheModel.phone           = 5;
                    cacheModel.sms             = 5;
                    cacheModel.smsEnableFlag   = true;
                    cacheModel.call_num        = 0;
                    cacheModel.max_humidity    = item.max_humidity;
                    cacheModel.min_humidity    = item.min_humidity;
                    cacheModel.max_temperature = item.max_temperature;
                    cacheModel.min_temperature = item.min_temperature;
                    cacheModel.warning_ammonia_concentration = item.warning_ammonia_concentration;
                    cacheModel.warning_negative_pressure     = item.warning_negative_pressure;
                    cacheModel.name            = item.name;
                    cacheModel.status          = equip.status;
                    cacheModel.username        = member.username;
                    cacheModel.warning_mobile  = equip.warning_mobile;
                    cacheModel.currentTemp     = "0";
                    cacheModel.currentHumidity = "0";
                    cacheModel.currentPower    = "0";
                    cacheModel.setDate         = DateTime.Now.Date;
                    model.cacheModels.Add(cacheModel);
                }
            }

            #endregion

            return(Task.FromResult(model));
        }
Exemplo n.º 9
0
        public JsonResult noticeNum(string token)
        {
            try
            {
                if (string.IsNullOrEmpty(token))
                {
                    return(Json(new notoken {
                    }));
                }
                noticeNum model = new noticeNum();
                model.code   = 1;
                model.status = "success";
                int id = 0;
                //var cached = _cache.GetCacheByToken(token);
                var cache = CacheUntity.GetCache <UserCacheModel>(token);
                id = cache.member.id.ToInt();
                var user        = _adminRepository.GetByID(id);
                var smssum      = 0;
                var call_numsum = 0;
                var phonesum    = 0;
                foreach (var item in cache.birdhouses)
                {
                    if (CacheUntity.Exists(item.equipment_id))
                    {
                        var devicecache = CacheUntity.GetCache <CacheModel>(item.equipment_id);
                        smssum   += devicecache.sms;
                        phonesum += devicecache.phone;
                    }
                    else
                    {
                        smssum   += 5;
                        phonesum += 5;
                    }
                }
                model.data = new noticeNumData
                {
                    sms            = smssum,
                    call_num       = call_numsum,
                    phone          = phonesum,
                    smsEnableFlag  = "enabled",
                    warning_mobile = JsonConvert.DeserializeObject <List <string> >(cache.member.warning_mobile)
                };

                return(Json(model));
            }
            catch (Exception e)
            {
                LogHelper.Error(JsonConvert.SerializeObject(e));
                return(Json(new nologin()));
            }
        }
Exemplo n.º 10
0
        public JsonResult login()
        {
            var mobile = Request.Query["mobile"][0];
            var code   = Request.Query["code"][0];

            if (code == _sms_Logs.GetBymobile(mobile).code&& _sms_Logs.GetBymobile(mobile).end_time.ToInt() >= Util.ToUnixStamp(DateTime.Now))
            {
                if (_memberRepository.GetBymobile(mobile) != null)
                {
                }
                else
                {
                    _memberRepository.Add(new Models.Member
                    {
                        create_time = Util.ToUnixStamp(DateTime.Now).ToString()
                        ,
                        mobile   = mobile,
                        username = mobile
                        ,
                        nick_name      = mobile,
                        update_time    = Util.ToUnixStamp(DateTime.Now).ToString(),
                        warning_mobile = ""
                    });
                }

                var user  = _memberRepository.GetBymobile(mobile);
                var token = Guid.NewGuid().ToString().Replace("-", "");
                var model = _cache.FillCacheWithToken(token, user);
                //string res = CacheUntity.GetCache<string>("test");

                CacheUntity.Init(new RedisCacheHelper());
                CacheUntity.SetCache(token, model.Result);
                //_cache.InsertCache(model.Result);
                login log = new login();
                log.code   = "1";
                log.status = "success";
                log.data   = new loginData {
                    code = code, create_time = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), id = user.id.ToInt(), mobile = mobile, update_time = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), end_time = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), token = token
                };
                return(Json(log));
            }
            else
            {
                loginerr logerr = new loginerr();
                logerr.code   = "-1";
                logerr.status = "fail";
                logerr.msg    = "验证码错误";
                return(Json(logerr));
            }
        }
Exemplo n.º 11
0
 public JsonResult index([FromBody] Addbirdhouse value)
 {
     try
     {
         var token = value.token;
         var cache = CacheUntity.GetCache <UserCacheModel>(token);
         var temp  = _equipment.GetByserial(value.equipment_id);
         if (temp == null)
         {
             return(Json(new { code = 0, status = "fail", msg = "非法设备" }));
         }
         else if (temp.bind_status == "1")
         {
             return(Json(new { code = 0, status = "fail", msg = "已绑定设备" }));
         }
         var       equip = _equipment.GetByserial(value.equipment_id);
         Birdhouse BIRD  = new Birdhouse();
         BIRD.name            = value.name;
         BIRD.member_id       = cache.member.id;
         BIRD.equipment_id    = value.equipment_id;
         BIRD.max_humidity    = "100";
         BIRD.max_temperature = "70";
         BIRD.min_humidity    = "30";
         BIRD.min_temperature = "10";
         BIRD.type            = value.type;
         BIRD.warning_ammonia_concentration = "0";
         BIRD.warning_negative_pressure     = "0";
         BIRD.create_time = Util.ToUnixStamp(DateTime.Now).ToString();
         BIRD.update_time = Util.ToUnixStamp(DateTime.Now).ToString();
         _birdhouse.Add(BIRD);
         equip.member_id = cache.member.id;
         //equip.name = value.name;
         //equip.serial = value.equipment_id;
         equip.status       = "1";
         equip.bind_status  = "1";
         equip.birdhouse_id = BIRD.id;
         equip.update_time  = Util.ToUnixStamp(DateTime.Now).ToString();
         _equipment.Update(equip);
         var model = _cache.FillCacheWithToken(token, cache.member);
         CacheUntity.SetCache(token, model.Result);
         return(Json(new { code = 1, status = "success", msg = "添加成功" }));
     }
     catch (Exception e)
     {
         LogHelper.Error(JsonConvert.SerializeObject(e));
         return(Json(new nologin()));
     }
 }
Exemplo n.º 12
0
 public JsonResult setWarningMobile([FromBody] setWarningMobileModel model)
 {
     try
     {
         var warning_mobile = model.warning_mobile;
         var token          = model.token;
         if (string.IsNullOrEmpty(token))
         {
             return(Json(new notoken {
             }));
         }
         var id    = 0;
         var cache = CacheUntity.GetCache <UserCacheModel>(token);
         //var cached = _cache.GetCacheByToken(token);
         id = cache.member.id.ToInt();
         var user = _adminRepository.GetByID(id);
         //List<string> mobiles = JsonConvert.DeserializeObject<List<string>>(warning_mobile);
         //user.warning_mobile = JsonConvert.SerializeObject(mobiles);
         user.warning_mobile = JsonConvert.SerializeObject(warning_mobile, Formatting.None, new JsonSerializerSettings {
             NullValueHandling = NullValueHandling.Ignore,
         });
         user.update_time = Util.ToUnixStamp(DateTime.Now).ToString();
         if (string.IsNullOrEmpty(user.nick_name))
         {
             user.nick_name = user.mobile;
         }
         if (string.IsNullOrEmpty(user.avatar))
         {
             user.avatar = "";
         }
         _adminRepository.Update(user);
         cache.member.warning_mobile = user.warning_mobile;
         var model1 = _cache.FillCacheWithToken(token, cache.member);
         CacheUntity.SetCache(token, model1.Result);
         return(Json(new setWarningMobile()));
     }
     catch (Exception e)
     {
         LogHelper.Error(JsonConvert.SerializeObject(e));
         return(Json(new nologin()));
     }
 }
Exemplo n.º 13
0
 public JsonResult equipmentList()
 {
     try
     {
         var token = Request.Query["token"][0];
         //var cached = _cache.GetCacheByToken(token);
         var cache     = CacheUntity.GetCache <UserCacheModel>(token);
         var member_id = cache.member.id.ToInt();
         var list      = cache.birdhouses;
         //if (list == null)
         {
             list = _bird.GetAll().ToList().Where(x => x.member_id == member_id.ToString()).ToList();
         }
         return(Json(new { code = 1, status = "success", msg = "ok", data = list }));
     }
     catch (Exception e)
     {
         LogHelper.Error(JsonConvert.SerializeObject(e));
         return(Json(new nologin()));
     }
 }
Exemplo n.º 14
0
        public JsonResult index()
        {
            try
            {
                var token = Request.Query["token"][0];
                if (string.IsNullOrEmpty(token))
                {
                    return(Json(new notoken {
                    }));
                }
                var id = "";
                if (Request.Query["id"].Count > 0)
                {
                    id = Request.Query["id"][0];
                }
                var cache = CacheUntity.GetCache <UserCacheModel>(token);

                if (string.IsNullOrEmpty(id))
                {
                    birdhouseindex index = new birdhouseindex();
                    index.code = "1";
                    index.data = new birdhouseData();
                    //if (cache.birdhouses == null|| cache.birdhouses.Count==0)
                    {
                        var list = _birdhouse.GetAll().Where(x => x.member_id == cache.member.id.ToString()).ToList();
                        cache.birdhouses = list;
                    }
                    index.data.total        = cache.birdhouses.Count;
                    index.data.current_page = 1;
                    index.data.last_page    = 1;
                    index.data.per_page     = 15;
                    index.data.data         = new List <birdhouseDataItem>();
                    foreach (var item in cache.birdhouses)
                    {
                        index.data.data.Add(new birdhouseDataItem
                        {
                            id              = item.id.ToInt(),
                            create_time     = item.create_time,
                            equipment_id    = item.equipment_id,
                            max_humidity    = item.max_humidity,
                            max_temperature = item.max_temperature,
                            member_id       = item.member_id.ToInt(),
                            min_humidity    = item.min_humidity,
                            min_temperature = item.min_temperature,
                            name            = item.name,
                            type            = item.type.ToInt(),
                            warning_ammonia_concentration = item.warning_ammonia_concentration,
                            warning_negative_pressure     = item.warning_negative_pressure,
                        });
                    }
                    index.status = "success";
                    return(Json(index));
                }
                else
                {
                    birdhouseindexWithid index = new birdhouseindexWithid();
                    index.status = "success";
                    index.code   = "1";
                    var item = _birdhouse.GetAll().Where(x => x.id == id && x.member_id == cache.member.id.ToString()).FirstOrDefault();
                    index.data = new birdhouseDataItem
                    {
                        id              = item.id.ToInt(),
                        create_time     = item.create_time,
                        equipment_id    = item.equipment_id,
                        max_humidity    = item.max_humidity,
                        max_temperature = item.max_temperature,
                        member_id       = item.member_id.ToInt(),
                        min_humidity    = item.min_humidity,
                        min_temperature = item.min_temperature,
                        name            = item.name,
                        type            = item.type.ToInt(),
                        warning_ammonia_concentration = item.warning_ammonia_concentration,
                        warning_negative_pressure     = item.warning_negative_pressure,
                    };
                    return(Json(index));
                }
            }
            catch (Exception e)
            {
                LogHelper.Error(JsonConvert.SerializeObject(e));
                return(Json(new nologin()));
            }
        }
Exemplo n.º 15
0
        public JsonResult Call([FromBody] CallCallback data)
        {
            //$tel = $data['cdr'][0]['tel'];
            //$desc = $data['cdr'][0]['stateDesc'];

            //if (in_array($desc, $this->status))
            //{
            //$info = (new \app\common\model\Member())->where('warning_mobile', 'like', "%{$tel}%")->find();

            //    Log::write($tel. ' ---- '. $desc);
            //$num = count($info['warning_mobile']);
            //    if ($num > 1 && $tel != $info['warning_mobile'][$num - 1]) {
            //    $content = json_decode(Cache::get($tel. '_warning'), true);
            //    $key = array_search($tel, $info['warning_mobile']);
            //    $sendCall = new SendCall();
            //    $status = $sendCall->templateNoticeCall($info['warning_mobile'][$key + 1], '01053182632', $content);
            //        Cache::set($info['warning_mobile'][$key + 1]. '_warning', json_encode($content));
            //        Log::write('被叫电话:'. $info['warning_mobile'][$key + 1]);
            //        Log::write('提交状态:'. $status['statusCode']. "ID:". $status['requestId']);
            //        Cache::rm($tel. '_warning');
            //    }
            //}
            //else
            //{
            //    Log::write('全部打完');
            //    Cache::rm($tel. '_warning');
            //}
            LogHelper.Error("app/CallCallback/Call" + JsonConvert.SerializeObject(data));
            var mobile = data.cdr[0].tel;
            var desc   = data.cdr[0].stateDesc;

            if (status.Contains(desc))
            {
                LogHelper.Error("app/CallCallback/Call desc" + desc);
                var cacheModel = CacheUntity.GetCache <CacheWarningModel>(mobile);
                LogHelper.Error("app/CallCallback/Call cacheModel" + JsonConvert.SerializeObject(cacheModel));
                if (cacheModel.uncalledmobile != null && cacheModel.uncalledmobile.Count > 0)
                {
                    var newmobile  = cacheModel.uncalledmobile.First();
                    var callstatus = _call.templateNoticeCall(newmobile, "01053924437", cacheModel.birdhouse, cacheModel.content);
                    LogHelper.Error("时间: " + DateTime.Now.ToString() + "补发电话通知  " + callstatus + "被叫号码" + newmobile);
                    CacheWarningModel warncache = new CacheWarningModel();
                    warncache.mobile         = newmobile;
                    warncache.mobilelist     = cacheModel.mobilelist;
                    warncache.uncalledmobile = cacheModel.uncalledmobile;
                    warncache.uncalledmobile.Remove(newmobile);
                    warncache.calledmobile = cacheModel.calledmobile;
                    warncache.calledmobile.Add(newmobile);
                    warncache.birdhouse = cacheModel.birdhouse;
                    warncache.content   = cacheModel.content;
                    CacheUntity.SetCache(newmobile, warncache);
                    CacheUntity.RemoveCache(mobile);
                }
                else
                {
                    LogHelper.Error("全部打完");
                }
            }
            else
            {
                LogHelper.Error("CallCallback 时间: " + DateTime.Now.ToString() + "电话通知状态" + desc + "requestId:" + "被叫号码" + mobile);
            }

            return(Json("ok"));
        }
Exemplo n.º 16
0
        public async Task ProcessDATA(string data)
        {
            if (!string.IsNullOrEmpty(data) && data.Contains(","))
            {
                var arr = data.Split(',');
                if (data.EndsWith("\r\n"))
                {
                    var newSTR = arr[3].Replace("\r\n", "");
                    arr[3] = newSTR;
                }
                _sendData.SendToUid(arr[0], JsonConvert.SerializeObject(arr));
                LogHelper.Error("发送数据到ws" + arr[0] + "内容" + JsonConvert.SerializeObject(arr));
                var cache = CacheUntity.GetCache <CacheModel>(arr[0]);
                if (cache == null || cache.setDate < DateTime.Now.Date)
                {
                    if (cache == null)
                    {
                        LogHelper.Error("cache null ");
                    }
                    else
                    {
                        LogHelper.Error("cache  fail" + JsonConvert.SerializeObject(cache));
                    }

                    var model = new CacheModel();
                    model.serial = arr[0];
                    var equip = _equipment.GetCacheModelByserial(model.serial);
                    model.bind_status     = equip.bind_status;
                    model.birdhouse_name  = equip.birdhouse_name;
                    model.phone           = 5;
                    model.sms             = 5;
                    model.smsEnableFlag   = true;
                    model.call_num        = 0;
                    model.max_humidity    = equip.max_humidity;
                    model.min_humidity    = equip.min_humidity;
                    model.max_temperature = equip.max_temperature;
                    model.min_temperature = equip.min_temperature;
                    model.warning_ammonia_concentration = equip.warning_ammonia_concentration;
                    model.warning_negative_pressure     = equip.warning_negative_pressure;
                    model.name            = equip.name;
                    model.status          = equip.status;
                    model.username        = equip.username;
                    model.warning_mobile  = equip.warning_mobile;
                    model.currentTemp     = arr[1];
                    model.currentHumidity = arr[2];
                    model.currentPower    = arr[3];
                    model.setDate         = DateTime.Now.Date;
                    CacheUntity.SetCache(arr[0], model);
                    cache = model;
                }
                //找到对应设备
                if (!string.IsNullOrEmpty(cache.warning_mobile) && cache.serial == arr[0])
                {
                    var cachemodel      = cache;
                    var equipmentStatus = 0;
                    if (!string.IsNullOrEmpty(cachemodel.min_temperature) && !string.IsNullOrEmpty(cachemodel.warning_mobile))
                    {
                        if (arr[1].ToFloat() < cachemodel.min_temperature.ToFloat() || arr[1].ToFloat() > cachemodel.max_temperature.ToFloat())
                        {
                            equipmentStatus += 10;
                            LogHelper.Error("temperature " + arr[1] + "min_temperature" + cachemodel.min_temperature + "max_temperature" + cachemodel.max_temperature);
                        }
                    }

                    if (!string.IsNullOrEmpty(cachemodel.min_humidity) && !string.IsNullOrEmpty(cachemodel.max_humidity))
                    {
                        if (arr[2].ToFloat() < cachemodel.min_humidity.ToFloat() || arr[2].ToFloat() > cachemodel.max_humidity.ToFloat())
                        {
                            equipmentStatus += 20;
                            LogHelper.Error("temperature " + arr[2] + "min_humidity" + cachemodel.min_humidity + "max_humidity" + cachemodel.max_humidity);
                        }
                    }

                    ////如果之前温室度出现过异常,只有温度和湿度全部改为正常后,才将可发送短息标志位 重置为 可启用
                    if (equipmentStatus == 0)
                    {
                        //如果温湿度正常,则将启用短信发送  重新置为 可用
                        cachemodel.smsEnableFlag = true;
                        //_cache.UpdateCache(cachemodel);
                        CacheUntity.SetCache(arr[0], cachemodel);
                    }

                    //// 判断设备是否断电
                    if (arr[3].ToInt() == 1)
                    {
                        equipmentStatus += 40;
                    }

                    //获取第一个报警电话
                    var mobile     = JsonConvert.DeserializeObject <List <string> >(cachemodel.warning_mobile).First();
                    var mobileList = JsonConvert.DeserializeObject <List <string> >(cachemodel.warning_mobile);
                    //    //进行报警
                    switch (equipmentStatus)
                    {
                    case 10:
                        //判断短信剩余数量,以及短信发送标识,如果为enabled则发送
                        if (cachemodel.sms > 0 && cachemodel.smsEnableFlag == true)
                        {
                            //发送短信
                            var status = _sms.sendSms(mobile, 2, cachemodel.birdhouse_name, "温度");
                            if (status.Result)
                            {
                                cachemodel.sms -= 1;
                                //异常则将短信启用发送标志位置为 不可用,也就是不再发送短信,除非重新接受到设备发来的数据判断为正常则
                                //重新将短信启用标志位 置为  可用
                                cachemodel.smsEnableFlag = false;
                                //_cache.UpdateCache(cachemodel);
                                CacheUntity.SetCache(arr[0], cachemodel);
                                LogHelper.Error("温度-短信:数据" + data + "设置" + JsonConvert.SerializeObject(cachemodel));
                            }
                        }

                        break;

                    case 20:
                        if (cachemodel.sms > 0 && cachemodel.smsEnableFlag == true)
                        {
                            var status = _sms.sendSms(mobile, 2, cachemodel.birdhouse_name, "湿度");
                            if (status.Result)
                            {
                                cachemodel.sms          -= 1;
                                cachemodel.smsEnableFlag = false;
                                CacheUntity.SetCache(arr[0], cachemodel);
                                LogHelper.Error("湿度-短信:数据" + data + "设置" + JsonConvert.SerializeObject(cachemodel));
                            }
                        }
                        break;

                    case 30:
                        if (cachemodel.sms > 0 && cachemodel.smsEnableFlag == true)
                        {
                            var status = _sms.sendSms(mobile, 2, cachemodel.birdhouse_name, "温度和湿度");
                            if (status.Result)
                            {
                                cachemodel.sms          -= 1;
                                cachemodel.smsEnableFlag = false;
                                CacheUntity.SetCache(arr[0], cachemodel);
                                LogHelper.Error("温度和湿度-短信" + data + "设置" + JsonConvert.SerializeObject(cachemodel));
                            }
                        }
                        break;

                    case 40:
                        //判断电话剩余数量
                        if (cachemodel.phone > 0)
                        {
                            //如果是第三次发送进入报警
                            if (cachemodel.call_num >= 2)
                            {
                                LogHelper.Error("开始报警-短信");
                                var content = "电源";
                                //拨打电话
                                CacheWarningModel warncache = new CacheWarningModel();
                                warncache.mobile         = mobile;
                                warncache.mobilelist     = mobileList;
                                warncache.uncalledmobile = mobileList;
                                warncache.uncalledmobile.Remove(mobile);
                                warncache.calledmobile = mobileList;
                                warncache.calledmobile.Clear();
                                warncache.calledmobile.Add(mobile);
                                warncache.birdhouse = cachemodel.birdhouse_name;
                                warncache.birdhouse = content;
                                CacheUntity.SetCache(mobile, warncache);
                                var status = _call.templateNoticeCall(mobile, "01053924437", cachemodel.birdhouse_name, content);
                                LogHelper.Error("时间: " + DateTime.Now.ToString() + "第1次电话通知状态" + status + "requestId:" + "被叫号码" + mobile);
                                if (!status.Result && mobileList.Count > 1)
                                {
                                    var mobile1 = mobileList[1];
                                    status = _call.templateNoticeCall(mobile1, "01053924437", cachemodel.birdhouse_name, content);
                                    LogHelper.Error("时间: " + DateTime.Now.ToString() + "第2次电话通知状态" + status + "requestId:" + "被叫号码" + mobile1);
                                    if (!status.Result && mobileList.Count > 2)
                                    {
                                        var mobile2 = mobileList[2];
                                        status = _call.templateNoticeCall(mobile2, "01053924437", cachemodel.birdhouse_name, content);
                                        LogHelper.Error("时间: " + DateTime.Now.ToString() + "第3次电话通知状态" + status + "requestId:" + "被叫号码" + mobile2);
                                    }
                                }
                                else
                                {
                                }
                                LogHelper.Error("电源-电话" + data + "设置" + JsonConvert.SerializeObject(cachemodel));
                                cachemodel.call_num = 0;
                                CacheUntity.SetCache(arr[0], cachemodel);
                                LogHelper.Error("时间: " + DateTime.Now.ToString() + "电话通知状态" + status + "requestId:" + "被叫号码" + mobile);
                                cachemodel.phone -= 1;
                            }
                            else
                            {
                                cachemodel.call_num += 1;
                                CacheUntity.SetCache(arr[0], cachemodel);
                            }
                        }

                        break;

                    case 50:
                        if (cachemodel.phone > 0)
                        {
                            if (cachemodel.call_num >= 2)
                            {
                                var content = "电源和温度";
                                var status  = _call.templateNoticeCall(mobile, "01053924437", cachemodel.birdhouse_name, content);
                                LogHelper.Error("时间: " + DateTime.Now.ToString() + "第1次电话通知状态" + status + "requestId:" + "被叫号码" + mobile);
                                if (!status.Result && mobileList.Count > 1)
                                {
                                    var mobile1 = mobileList[1];
                                    status = _call.templateNoticeCall(mobile1, "01053924437", cachemodel.birdhouse_name, content);
                                    LogHelper.Error("时间: " + DateTime.Now.ToString() + "第2次电话通知状态" + status + "requestId:" + "被叫号码" + mobile1);
                                    if (!status.Result && mobileList.Count > 2)
                                    {
                                        var mobile2 = mobileList[2];
                                        status = _call.templateNoticeCall(mobile2, "01053924437", cachemodel.birdhouse_name, content);
                                        LogHelper.Error("时间: " + DateTime.Now.ToString() + "第3次电话通知状态" + status + "requestId:" + "被叫号码" + mobile2);
                                    }
                                }
                                LogHelper.Error("电源和温度-电话" + data + "设置" + JsonConvert.SerializeObject(cachemodel));
                                cachemodel.call_num = 0;
                                CacheUntity.SetCache(arr[0], cachemodel);
                                cachemodel.phone -= 1;
                                CacheUntity.SetCache(arr[0], cachemodel);
                            }
                            else
                            {
                                cachemodel.call_num += 1;
                                CacheUntity.SetCache(arr[0], cachemodel);
                            }
                        }

                        break;

                    case 60:
                        if (cachemodel.phone > 0)
                        {
                            if (cachemodel.call_num >= 2)
                            {
                                var content = "电源和湿度";
                                var status  = _call.templateNoticeCall(mobile, "01053182632", cachemodel.birdhouse_name, content);
                                LogHelper.Error("时间: " + DateTime.Now.ToString() + "第1次电话通知状态" + status + "requestId:" + "被叫号码" + mobile);
                                if (!status.Result && mobileList.Count > 1)
                                {
                                    var mobile1 = mobileList[1];
                                    status = _call.templateNoticeCall(mobile1, "01053924437", cachemodel.birdhouse_name, content);
                                    LogHelper.Error("时间: " + DateTime.Now.ToString() + "第2次电话通知状态" + status + "requestId:" + "被叫号码" + mobile1);
                                    if (!status.Result && mobileList.Count > 2)
                                    {
                                        var mobile2 = mobileList[2];
                                        status = _call.templateNoticeCall(mobile2, "01053924437", cachemodel.birdhouse_name, content);
                                        LogHelper.Error("时间: " + DateTime.Now.ToString() + "第3次电话通知状态" + status + "requestId:" + "被叫号码" + mobile2);
                                    }
                                }
                                LogHelper.Error("电源和湿度-电话" + data + "设置" + JsonConvert.SerializeObject(cachemodel));
                                cachemodel.call_num = 0;
                                CacheUntity.SetCache(arr[0], cachemodel);
                                cachemodel.phone -= 1;
                                CacheUntity.SetCache(arr[0], cachemodel);
                            }
                            else
                            {
                                cachemodel.call_num += 1;
                                CacheUntity.SetCache(arr[0], cachemodel);
                            }
                        }

                        break;

                    case 70:
                        if (cachemodel.phone > 0)
                        {
                            if (cachemodel.call_num >= 2)
                            {
                                var content = "电源,湿度和温度";
                                //var status  = _call.templateNoticeCall(mobile, "01053182632", cachemodel.birdhouse_name, content);
                                var status = _call.templateNoticeCall(mobile, "01053182632", cachemodel.birdhouse_name, content);
                                LogHelper.Error("时间: " + DateTime.Now.ToString() + "第1次电话通知状态" + status + "requestId:" + "被叫号码" + mobile);
                                if (!status.Result && mobileList.Count > 1)
                                {
                                    var mobile1 = mobileList[1];
                                    status = _call.templateNoticeCall(mobile1, "01053924437", cachemodel.birdhouse_name, content);
                                    LogHelper.Error("时间: " + DateTime.Now.ToString() + "第2次电话通知状态" + status + "requestId:" + "被叫号码" + mobile1);
                                    if (!status.Result && mobileList.Count > 2)
                                    {
                                        var mobile2 = mobileList[2];
                                        status = _call.templateNoticeCall(mobile2, "01053924437", cachemodel.birdhouse_name, content);
                                        LogHelper.Error("时间: " + DateTime.Now.ToString() + "第3次电话通知状态" + status + "requestId:" + "被叫号码" + mobile2);
                                    }
                                }
                                LogHelper.Error("电源,湿度和温度-电话" + data + "设置" + JsonConvert.SerializeObject(cachemodel));
                                cachemodel.call_num = 0;
                                CacheUntity.SetCache(arr[0], cachemodel);
                                cachemodel.phone -= 1;
                                CacheUntity.SetCache(arr[0], cachemodel);
                            }
                            else
                            {
                                cachemodel.call_num += 1;
                                CacheUntity.SetCache(arr[0], cachemodel);
                            }
                        }

                        break;
                    }
                }


                /////记录
                var log = new Equipment_status_logs();
                log.humidity     = arr[2];
                log.power_status = arr[3].ToInt();
                log.serial       = arr[0];
                log.temperature  = arr[1];
                log.create_time  = Util.ToUnixStamp(DateTime.Now).ToString();
                log.update_time  = Util.ToUnixStamp(DateTime.Now).ToString();
                _logsRepo.Add(log);
            }


            //通知websocket
            //if ($res) {
            //$connection->send('yes');
            //} else {
            //$connection->send('no');
        }