/// <summary>
        /// 查询该用户所有网关下所有情景面板
        /// </summary>
        /// <param name="openId">用户微信的唯一值</param>
        /// <returns></returns>
        public JsonResult GetUserAllScene(string openId)
        {
            //使用SQl语句嵌套查询
            string sql = "SELECT * FROM iot_scene_panel WHERE GateWayID IN ( " +
                         "SELECT GateWayID FROM iot_user_gateway WHERE UserId = (" +
                         $"SELECT UserId FROM iot_user WHERE OpenId = '{openId}'))";
            var temp = db.Database.SqlQuery <iot_scene_panel>(sql).ToList();

            if (temp == null)
            {
                return(Json(new { statu = StatusCode.NotFound, Message = "未找到任何设备" }, JsonRequestBehavior.AllowGet));
            }
            List <iot_scene_panel> list = new List <iot_scene_panel>();

            //将得到的数据使用result保存起来
            foreach (var item in temp)
            {
                var result = new iot_scene_panel
                {
                    ID         = item.ID,
                    GateWayId  = item.GateWayId,
                    Name       = item.Name,
                    Uid        = item.Uid,
                    Position   = item.Position,
                    CreateTime = item.CreateTime,
                    EditTime   = item.EditTime
                };
                list.Add(result);
            }
            return(Json(list, JsonRequestBehavior.AllowGet));
        }
        public JsonResult AddScenePanel([System.Web.Http.FromBody] iot_scene_panel model)
        {
            var count = db.iot_scene_panel.Where(s => s.Uid.Equals(model.Uid));

            if (count.Count() > 0)
            {
                return(Json(new { status = StatusCode.FAIL, meassage = "该设备已被添加,请勿重复添加" }));
            }
            iot_scene_panel data =
                new iot_scene_panel
            {
                //网关信息为用户选择绑定在那个网关
                GateWayId = model.GateWayId,
                Name      = model.Name,
                //Uid为用户使用二维码扫描后自动获取
                Uid        = model.Uid,
                CreateTime = new DateTime().Date,
                EditTime   = null
            };
            //判断是否需要从空值表中得到position数据
            int position = util.GetGateWayPositon(3, model.GateWayId);

            data.Position = position;

            //进行判断该网关下该设备是否达到承载最大值
            if (position > 15)
            {
                return(Json(new { status = StatusCode.FAIL, message = "情景面板负载达到最大值" }));
            }
            db.iot_scene_panel.Add(data);
            int uprows = db.SaveChanges();

            var taskinfo = new { status = StatusCode.SUCCESS, message = "添加成功" };

            if (uprows < 1)
            {
                taskinfo = new { status = StatusCode.FAIL, message = "添加失败" };
            }

            return(Json(taskinfo, JsonRequestBehavior.AllowGet));
        }