Exemplo n.º 1
0
        public IHttpActionResult DeviceAddChart(HomeConfigurationModel model)
        {
            UserApi api     = new UserApi();
            var     userApi = api.GetUserInfoByToken();

            model.DashBoardType = "1";
            model.CreateUserID  = userApi.Data.UserId;
            model.OrgID         = userApi.Data.OrgID.ToString();
            HomeConfigurationBLL   device        = new HomeConfigurationBLL();
            DashBoardDataListModel DashBoardData = new DashBoardDataListModel()
            {
                x = 0,
                y = 0,
                w = Convert.ToInt32(model.Width),
                h = Convert.ToInt32(model.Height)
            };

            model.DashBoardData = JsonConvert.SerializeObject(DashBoardData);
            model.DatabaseType  = "0";//默认设备源
            DashBoardChartConfigModel ChartConfig = new DashBoardChartConfigModel()
            {
                DatabaseType        = model.DatabaseType,
                DataType            = model.DataType,
                RecentInterval      = model.RecentInterval,
                RecentUnit          = model.RecentUnit,
                StartTime           = model.StartTime.ToString(),
                EndTime             = model.EndTime.ToString(),
                StatisticalInterval = model.StatisticalInterval,
                IntervalUnit        = model.IntervalUnit,
                MinValue            = model.MinValue,
                MaxValue            = model.MaxValue,
                ValueType           = model.ValueType,
                TextColor           = model.TextColor,
                BackgroundColor     = model.BackgroundColor
            };
            List <HomeDeviceInfo> HomeDeviceInfoList = new List <HomeDeviceInfo>();

            if (model.DeviceItemList != null)
            {
                for (int i = 0; i < model.DeviceItemList.Count; i++)
                {
                    HomeDeviceInfo HomeDeviceInfo = new HomeDeviceInfo();
                    HomeDeviceInfo.DeviceID     = model.DeviceID;
                    HomeDeviceInfo.DeviceItemID = model.DeviceItemList[i].DeviceItemID;
                    HomeDeviceInfoList.Add(HomeDeviceInfo);
                }
            }
            ChartConfig.HomeDeviceInfoList = HomeDeviceInfoList;
            model.ChartConfig = JsonConvert.SerializeObject(ChartConfig);

            var add = device.AddChart(model);

            return(InspurJson <RetHomeConfiguration>(add));
        }
Exemplo n.º 2
0
        public IHttpActionResult EditChart(HomeConfigurationModel model)
        {
            HomeConfigurationBLL   device        = new HomeConfigurationBLL();
            DashBoardDataListModel DashBoardData = new DashBoardDataListModel()
            {
                x = Convert.ToInt32(model.XAxis),
                y = Convert.ToInt32(model.YAxis),
                w = Convert.ToInt32(model.Width),
                h = Convert.ToInt32(model.Height),
                i = model.ID.ToString()
            };

            model.DashBoardData = JsonConvert.SerializeObject(DashBoardData);
            model.DatabaseType  = "0";//默认设备源
            DashBoardChartConfigModel ChartConfig = new DashBoardChartConfigModel()
            {
                DatabaseType        = model.DatabaseType,
                DataType            = model.DataType,
                RecentInterval      = model.RecentInterval,
                RecentUnit          = model.RecentUnit,
                StartTime           = model.StartTime.ToString(),
                EndTime             = model.EndTime.ToString(),
                StatisticalInterval = model.StatisticalInterval,
                IntervalUnit        = model.IntervalUnit,
                MinValue            = model.MinValue,
                MaxValue            = model.MaxValue,
                ValueType           = model.ValueType,
                TextColor           = model.TextColor,
                BackgroundColor     = model.BackgroundColor
            };
            List <HomeDeviceInfo> HomeDeviceInfoList = new List <HomeDeviceInfo>();

            if (model.DeviceItemList != null)
            {
                for (int i = 0; i < model.DeviceItemList.Count; i++)
                {
                    HomeDeviceInfo HomeDeviceInfo = new HomeDeviceInfo();
                    HomeDeviceInfo.DeviceID     = model.DeviceID;
                    HomeDeviceInfo.DeviceItemID = model.DeviceItemList[i].DeviceItemID;
                    HomeDeviceInfoList.Add(HomeDeviceInfo);
                }
            }
            ChartConfig.HomeDeviceInfoList = HomeDeviceInfoList;
            model.ChartConfig = JsonConvert.SerializeObject(ChartConfig);

            var update = device.EditChart(model);

            return(InspurJson <RetHomeConfiguration>(update));
        }
        /// <summary>
        /// 获取图表列表
        /// </summary>
        /// <returns>成功返回图表列表,失败返回Null.</returns>
        public ReturnItem <List <RetHomeConfiguration> > GetChartList(HomeConfigurationModel parameter)
        {
            ReturnItem <List <RetHomeConfiguration> > r = new ReturnItem <List <RetHomeConfiguration> >();
            List <RetHomeConfiguration> listinfo        = new List <RetHomeConfiguration>();

            using (UserEntities user = new UserEntities())
            {
                try
                {
                    var deviceid      = Convert.ToInt32(parameter.DeviceID);
                    var dashboardtype = Convert.ToInt32(parameter.DashBoardType);
                    var getchartlist  = new List <U_HomeConfiguration>();
                    if (dashboardtype == 0)
                    {
                        var OrgID = Convert.ToInt32(parameter.OrgID);
                        getchartlist = user.U_HomeConfiguration.Where(s => s.DashBoardType == dashboardtype && s.OrgID == OrgID).ToList();
                    }
                    else if (dashboardtype == 1)
                    {
                        getchartlist = user.U_HomeConfiguration.Where(s => s.DeviceID == deviceid && s.DashBoardType == dashboardtype).ToList();
                    }
                    if (getchartlist.Count == 0 || getchartlist == null)
                    {
                        r.Data = null;
                        r.Code = -1;
                        r.Msg  = "未找到设备图表";
                        return(r);
                    }
                    if (getchartlist != null && getchartlist.Count != 0)
                    {
                        List <U_HomeConfiguration> list = getchartlist.ToList <U_HomeConfiguration>();
                        r.Count = getchartlist.Count();
                        r.Msg   = "设备信息获取成功";
                        r.Code  = 0;
                        foreach (var item in list)
                        {
                            var chartlistinfo = new RetHomeConfiguration();
                            chartlistinfo.ID            = item.ID;
                            chartlistinfo.DashBoardType = item.DashBoardType.ToString();
                            chartlistinfo.DeviceID      = item.DeviceID.ToString();
                            chartlistinfo.DeviceItemID  = item.DeviceItemID.ToString();
                            chartlistinfo.ChartName     = item.ChartName.ToString();
                            chartlistinfo.ChartType     = item.ChartType.ToString();
                            // ChartConfig赋值
                            chartlistinfo.ChartConfig = item.ChartConfig;
                            DashBoardChartConfigModel ChartConfig = new DashBoardChartConfigModel();
                            if (item.ChartConfig != "" && item.ChartConfig != null)
                            {
                                ChartConfig = JsonConvert.DeserializeObject <DashBoardChartConfigModel>(item.ChartConfig);
                            }
                            chartlistinfo.DatabaseType   = ChartConfig.DatabaseType;
                            chartlistinfo.DataType       = ChartConfig.DataType;
                            chartlistinfo.RecentInterval = ChartConfig.RecentInterval;
                            chartlistinfo.RecentUnit     = ChartConfig.RecentUnit;
                            if (ChartConfig.StartTime != "")
                            {
                                chartlistinfo.StartTime = Convert.ToDateTime(ChartConfig.StartTime);
                            }
                            if (ChartConfig.EndTime != "")
                            {
                                chartlistinfo.EndTime = Convert.ToDateTime(ChartConfig.EndTime);
                            }
                            chartlistinfo.StatisticalInterval = ChartConfig.StatisticalInterval;
                            chartlistinfo.IntervalUnit        = ChartConfig.IntervalUnit;
                            chartlistinfo.MinValue            = ChartConfig.MinValue;
                            chartlistinfo.MaxValue            = ChartConfig.MaxValue;
                            chartlistinfo.ValueType           = ChartConfig.ValueType;
                            chartlistinfo.TextColor           = ChartConfig.TextColor;
                            chartlistinfo.BackgroundColor     = ChartConfig.BackgroundColor;
                            chartlistinfo.HomeDeviceInfoList  = ChartConfig.HomeDeviceInfoList;
                            //首页
                            if (item.DashBoardType == 0)
                            {
                                List <BaseModel> Property = new List <BaseModel>();
                                if (ChartConfig.SelectionType == "1") //设备
                                {
                                    foreach (var info in ChartConfig.HomeDeviceInfoList)
                                    {
                                        BaseModel     model = new BaseModel();
                                        List <string> data  = new List <string>();
                                        data.Add("1");
                                        data.Add(info.DeviceID);
                                        data.Add(info.DeviceItemID);
                                        model.data = data;
                                        Property.Add(model);
                                    }
                                }
                                else if (ChartConfig.SelectionType == "2")//总览
                                {
                                    BaseModel     model = new BaseModel();
                                    List <string> data  = new List <string>();
                                    data.Add("2");
                                    data.Add(ChartConfig.ValueType);
                                    model.data = data;
                                    Property.Add(model);
                                }
                                else if (ChartConfig.SelectionType == "3")//表格
                                {
                                    BaseModel     model = new BaseModel();
                                    List <string> data  = new List <string>();
                                    data.Add("3");
                                    data.Add(ChartConfig.ValueType);
                                    model.data = data;
                                    Property.Add(model);
                                }
                                chartlistinfo.Property = Property;
                            }
                            //设备
                            else if (item.DashBoardType == 1)
                            {
                                List <DeviceBaseModel> DeviceItemList = new List <DeviceBaseModel>();
                                foreach (var info in ChartConfig.HomeDeviceInfoList)
                                {
                                    DeviceBaseModel model = new DeviceBaseModel();
                                    model.DeviceItemID = info.DeviceItemID;
                                    DeviceItemList.Add(model);
                                }
                                chartlistinfo.DeviceItemList = DeviceItemList;
                            }
                            // DashBoardData赋值
                            chartlistinfo.DashBoardData = item.DashBoardData;
                            RetDashBoardDataList DashBoardData = new RetDashBoardDataList();
                            if (item.DashBoardData != "" && item.DashBoardData != null)
                            {
                                DashBoardData = JsonConvert.DeserializeObject <RetDashBoardDataList>(item.DashBoardData);
                            }
                            chartlistinfo.DashBoardDataList = DashBoardData;
                            chartlistinfo.Remark            = item.Remark;
                            chartlistinfo.SortID            = item.SortID;
                            chartlistinfo.CreateTime        = item.CreateTime;
                            chartlistinfo.CreateUserID      = item.CreateUserID.ToString();
                            chartlistinfo.OrgID             = item.OrgID.ToString();
                            listinfo.Add(chartlistinfo);
                        }
                        r.Data = listinfo;
                    }
                }
                catch (Exception e)
                {
                    r.Msg = "内部错误请重试";
                    log.ErrorFormat("内部错误:{0},{1}", e.Message, e.StackTrace);
                    r.Code = -1;
                }
            }

            return(r);
        }
        /// <summary>
        /// 利用ID获取图表列表
        /// </summary>
        public ReturnItem <RetHomeConfiguration> GetChart(HomeConfigurationModel parameter)
        {
            ReturnItem <RetHomeConfiguration> r = new ReturnItem <RetHomeConfiguration>();

            using (UserEntities user = new UserEntities())
            {
                try
                {
                    var getchart = user.U_HomeConfiguration.Where(s => s.ID == parameter.ID).FirstOrDefault();
                    if (getchart == null)
                    {
                        r.Data = null;
                        r.Code = -1;
                        r.Msg  = "未找到设备图表";
                        return(r);
                    }
                    if (getchart != null)
                    {
                        r.Msg  = "设备信息获取成功";
                        r.Code = 0;
                        r.Data = new RetHomeConfiguration()
                        {
                            ID            = getchart.ID,
                            DashBoardType = getchart.DashBoardType.ToString(),
                            DeviceID      = getchart.DeviceID.ToString(),
                            DeviceItemID  = getchart.DeviceItemID.ToString(),
                            ChartName     = getchart.ChartName.ToString(),
                            ChartType     = getchart.ChartType.ToString(),
                            ChartConfig   = getchart.ChartConfig,
                            DashBoardData = getchart.DashBoardData,
                            Remark        = getchart.Remark,
                            SortID        = getchart.SortID,
                            CreateTime    = getchart.CreateTime,
                            CreateUserID  = getchart.CreateUserID.ToString(),
                            OrgID         = getchart.OrgID.ToString()
                        };
                        // DashBoardData赋值
                        RetDashBoardDataList DashBoardData = new RetDashBoardDataList();
                        if (getchart.DashBoardData != "" && getchart.DashBoardData != null)
                        {
                            DashBoardData = JsonConvert.DeserializeObject <RetDashBoardDataList>(getchart.DashBoardData);
                        }
                        r.Data.DashBoardDataList = DashBoardData;
                        r.Data.XAxis             = DashBoardData.x.ToString();
                        r.Data.YAxis             = DashBoardData.y.ToString();
                        r.Data.Width             = DashBoardData.w.ToString();
                        r.Data.Height            = DashBoardData.h.ToString();
                        // ChartConfig赋值
                        DashBoardChartConfigModel ChartConfig = new DashBoardChartConfigModel();
                        if (getchart.ChartConfig != "" && getchart.ChartConfig != null)
                        {
                            ChartConfig = JsonConvert.DeserializeObject <DashBoardChartConfigModel>(getchart.ChartConfig);
                        }
                        r.Data.DatabaseType   = ChartConfig.DatabaseType;
                        r.Data.DataType       = ChartConfig.DataType;
                        r.Data.RecentInterval = ChartConfig.RecentInterval;
                        r.Data.RecentUnit     = ChartConfig.RecentUnit;
                        if (ChartConfig.StartTime != "")
                        {
                            r.Data.StartTime = Convert.ToDateTime(ChartConfig.StartTime);
                        }
                        if (ChartConfig.EndTime != "")
                        {
                            r.Data.EndTime = Convert.ToDateTime(ChartConfig.EndTime);
                        }
                        r.Data.StatisticalInterval = ChartConfig.StatisticalInterval;
                        r.Data.IntervalUnit        = ChartConfig.IntervalUnit;
                        r.Data.MinValue            = ChartConfig.MinValue;
                        r.Data.MaxValue            = ChartConfig.MaxValue;
                        r.Data.ValueType           = ChartConfig.ValueType;
                        r.Data.TextColor           = ChartConfig.TextColor;
                        r.Data.BackgroundColor     = ChartConfig.BackgroundColor;
                        r.Data.HomeDeviceInfoList  = ChartConfig.HomeDeviceInfoList;
                        //首页
                        if (getchart.DashBoardType == 0)
                        {
                            List <BaseModel> Property = new List <BaseModel>();
                            if (ChartConfig.SelectionType == "1") //设备
                            {
                                foreach (var info in ChartConfig.HomeDeviceInfoList)
                                {
                                    BaseModel     model = new BaseModel();
                                    List <string> data  = new List <string>();
                                    data.Add("1");
                                    data.Add(info.DeviceID);
                                    data.Add(info.DeviceItemID);
                                    model.data = data;
                                    Property.Add(model);
                                }
                            }
                            else if (ChartConfig.SelectionType == "2")//总览
                            {
                                BaseModel     model = new BaseModel();
                                List <string> data  = new List <string>();
                                data.Add("2");
                                data.Add(ChartConfig.ValueType);
                                model.data = data;
                                Property.Add(model);
                            }
                            else if (ChartConfig.SelectionType == "3")//表格
                            {
                                BaseModel     model = new BaseModel();
                                List <string> data  = new List <string>();
                                data.Add("3");
                                data.Add(ChartConfig.ValueType);
                                model.data = data;
                                Property.Add(model);
                            }
                            r.Data.Property = Property;
                        }
                        //设备
                        else if (getchart.DashBoardType == 1)
                        {
                            List <DeviceBaseModel> DeviceItemList = new List <DeviceBaseModel>();
                            foreach (var info in ChartConfig.HomeDeviceInfoList)
                            {
                                DeviceBaseModel model = new DeviceBaseModel();
                                model.DeviceItemID = info.DeviceItemID;
                                DeviceItemList.Add(model);
                            }
                            r.Data.DeviceItemList = DeviceItemList;
                        }
                    }
                }
                catch (Exception e)
                {
                    r.Msg = "内部错误请重试";
                    log.ErrorFormat("内部错误:{0},{1}", e.Message, e.StackTrace);
                    r.Code = -1;
                }
            }

            return(r);
        }
Exemplo n.º 5
0
        public IHttpActionResult IndexEditChart(HomeConfigurationModel model)
        {
            HomeConfigurationBLL device = new HomeConfigurationBLL();

            model.DashBoardType = "0";//首页
            DashBoardDataListModel DashBoardData = new DashBoardDataListModel()
            {
                x = Convert.ToInt32(model.XAxis),
                y = Convert.ToInt32(model.YAxis),
                w = Convert.ToInt32(model.Width),
                h = Convert.ToInt32(model.Height),
                i = model.ID.ToString()
            };

            model.DashBoardData = JsonConvert.SerializeObject(DashBoardData);

            DashBoardChartConfigModel ChartConfig = new DashBoardChartConfigModel()
            {
                DatabaseType        = model.DatabaseType,
                DataType            = model.DataType,
                RecentInterval      = model.RecentInterval,
                RecentUnit          = model.RecentUnit,
                StartTime           = model.StartTime.ToString(),
                EndTime             = model.EndTime.ToString(),
                StatisticalInterval = model.StatisticalInterval,
                IntervalUnit        = model.IntervalUnit,
                MinValue            = model.MinValue,
                MaxValue            = model.MaxValue,
                ValueType           = model.ValueType,
                TextColor           = model.TextColor,
                BackgroundColor     = model.BackgroundColor
            };
            List <HomeDeviceInfo> HomeDeviceInfoList = new List <HomeDeviceInfo>();

            if (model.Property != null)
            {
                if (model.Property.Count == 1) //设备,总览,表格
                {
                    if (model.Property[0].data[0] == "1")
                    {
                        // 设备
                        ChartConfig.SelectionType = "1";
                        HomeDeviceInfo HomeDeviceInfo = new HomeDeviceInfo();
                        HomeDeviceInfo.DeviceID     = model.Property[0].data[1];
                        HomeDeviceInfo.DeviceItemID = model.Property[0].data[2];
                        HomeDeviceInfoList.Add(HomeDeviceInfo);
                    }
                    else if (model.Property[0].data[0] == "2")
                    {
                        // 总览
                        ChartConfig.SelectionType = "2";
                    }
                    else if (model.Property[0].data[0] == "3")
                    {
                        // 表格
                        ChartConfig.SelectionType = "3";
                    }
                }
                else if (model.Property.Count > 1) //只可能设备
                {
                    for (int i = 0; i < model.Property.Count; i++)
                    {
                        ChartConfig.SelectionType = "1";
                        HomeDeviceInfo HomeDeviceInfo = new HomeDeviceInfo();
                        HomeDeviceInfo.DeviceID     = model.Property[i].data[1];
                        HomeDeviceInfo.DeviceItemID = model.Property[i].data[2];
                        HomeDeviceInfoList.Add(HomeDeviceInfo);
                    }
                }
            }
            ChartConfig.HomeDeviceInfoList = HomeDeviceInfoList;
            model.ChartConfig = JsonConvert.SerializeObject(ChartConfig);

            var update = device.EditChart(model);

            return(InspurJson <RetHomeConfiguration>(update));
        }